Relative date / today in Power Query IF / conditional column

Поділитися
Вставка
  • Опубліковано 13 лип 2024
  • Power Query's conditional columns are super easy but they cannot work with comparing relative dates, you need custom code for that, but once you understand it there are dozens of date functions in Power Query. Remember to Wrap Date.From() around our functions to explicitly set the date format and always use upper case. If you want a copy of this workbook, leave me a comment & subscribe to my channel.
    Learn all date functions here: docs.microsoft.com/en-us/powe...
    Functions I showcase:
    Today: Date.From(DateTime.LocalNow())
    One quarter ago: Date.From(Date.AddQuarters(DateTime.LocalNow(),-1))
    End of last month: Date.From(Date.EndOfMonth(DateTime.LocalNow()))
    00:00 - Introduction
    02:43 - Before today
    05:55 - Before one quarter ago
    08:44 - End of last month
    10:38 - Filtering based on a relative date
    11:54 - Date functions documentation
  • Навчання та стиль

КОМЕНТАРІ • 42

  • @erickbunch1987
    @erickbunch1987 Рік тому +1

    Great job mate! Exactly was I was looking for!

  • @dimaivanov6926
    @dimaivanov6926 2 роки тому

    You are a magician! Thanks a lot!!

  • @mariaroberts1600
    @mariaroberts1600 2 роки тому

    This was extremely helpful thank you very much for helping

  • @cewolf78
    @cewolf78 2 роки тому +1

    Thanks man ... I was looking for this

    • @learnspreadsheets
      @learnspreadsheets  2 роки тому

      Good to know! I just thought of it recently as a video - glad people find it useful!

  • @uma.naturelover
    @uma.naturelover 2 роки тому

    Loved it.. thank you for providing this -:)

  • @ilovepowerbi811
    @ilovepowerbi811 Рік тому +1

    Very good content, Please more video on power query

    • @learnspreadsheets
      @learnspreadsheets  Рік тому

      Thanksss love the feedback! Have a few ideas for future videos! I have quite a few on my channel already!

  • @kandake8930
    @kandake8930 Рік тому +1

    2 hours to find this solution 😅 Thank you!

  • @thomas9334
    @thomas9334 2 роки тому

    My Polish Power Querry had errors with the funkcion TODA(). Thanks to You I avoided this problem. Many Thanks.

    • @learnspreadsheets
      @learnspreadsheets  2 роки тому

      Yay! I’m so glad this video helped you! Thanks for the comment

  • @markp8600
    @markp8600 10 місяців тому

    David, thanks for the video -- would like a copy of the workbook. Thanks.

    • @learnspreadsheets
      @learnspreadsheets  10 місяців тому

      Sure! Get it at www.xlconsulting-asia.com/youtube-files.html

  • @ohhhnelly203
    @ohhhnelly203 Рік тому +1

    Hi David,
    Thanks for the video! I have a report that I need to filter out the current day and prior business day. Instead of -1 I used -2 in the code. But I need to account for weekends (if Monday, then filter out Monday and Friday of prior week). Is there a way to do this? I am not concerned about US Federal Bank Holidays, but if there is a way to account for that it would be a plus! Thanks!

    • @learnspreadsheets
      @learnspreadsheets  Рік тому

      Heya you will provably need a date table with public holidays & weekends & then use merge queries to remove it. My latest video is all about date tables in power bi, check it out

  • @dashingmozy111
    @dashingmozy111 2 роки тому

    Hi David, thanks for the video. Quick question about how to achieve following.
    Master table has values till yesterday (sales and region). I want to append Master table with today's values. I want to perform this automatically for every day. Since I am using SAP BW, Incremental refresh doesnt work (Query folding not available).
    I have tried to extract latest date from master table in a query (in my example, it is yesterday). Used the latest date query to fetch today's data (as start date). However while appending both tables, it throws cyclic error (rightfully so).
    I would really appreciate your guidance.
    Thanks!

    • @learnspreadsheets
      @learnspreadsheets  2 роки тому

      Sorry this is a pretty specific problem & I can’t help, maybe try one of the forums that way you can post images & the data itself maybe too

    • @dashingmozy111
      @dashingmozy111 2 роки тому

      @@learnspreadsheets sure, thank you again!

  • @Faisal63045
    @Faisal63045 Рік тому +1

    Hi is there a formula or PQ way to change any transactions time that come between 12:00:00 AM and 7:59:59 AM To be 8:00:00 AM which is the start of working hour.

    • @learnspreadsheets
      @learnspreadsheets  Рік тому

      Hi yes there should be, you should extract the time out of a cell to show on its own then an IF formula is capable

  • @OscarPerez-hi7hq
    @OscarPerez-hi7hq 2 роки тому

    How would you edit for one day less than today's date?

  • @biswanthpinnika7149
    @biswanthpinnika7149 2 роки тому

    Hi David, I have 2 date columns and one contains null values I want to replace the null value with previous date column can you solve this one..

    • @learnspreadsheets
      @learnspreadsheets  2 роки тому

      I would add a conditional column… if col1 is blank then col 2 otherwise col1, seems like that should work

    • @biswanthpinnika7149
      @biswanthpinnika7149 2 роки тому

      @@learnspreadsheets yes I applied it. It works

  • @ryqarst4690
    @ryqarst4690 2 місяці тому +1

    13min video for a 10 second answer @5:20

    • @learnspreadsheets
      @learnspreadsheets  2 місяці тому

      Glad you find it helpful. Others seem to as well 🙃

  • @caiocampos3748
    @caiocampos3748 Рік тому +1

    What I need is to create a column with Today() - "date" in order to know how many days I have...but I can't do it

    • @learnspreadsheets
      @learnspreadsheets  Рік тому

      Hi, this seems to work: = Table.AddColumn(#"Changed Type", "Custom", each Duration.Days([Date]-Date.From(DateTime.LocalNow())))

  • @3elperro
    @3elperro 8 місяців тому +1

    I'M TRYING TO FILTER MY DATES WITH POWER QUERY, I NEED TO SEE MY INVENTORY STARTING FROM 160 DAYS AFTER THE CURRENT DATE AND UP, BUT I CAN'T FIND MY WAY TO FILTER MY DATA THIS WAY... PLEASE HELP

    • @learnspreadsheets
      @learnspreadsheets  8 місяців тому

      Using the code I have in this video you can get the current date then wrap it inside a date.adddays function to move it 180 days in future. More here: learn.microsoft.com/en-us/powerquery-m/date-adddays

  • @PrincessDana005
    @PrincessDana005 2 роки тому

    I used Date.From(Date.EndOfMonth(DateTime.LocalNow())) in a blank query but I got the end of this month (5/31/2022) , I want the end of last month (4/30/2022). I played around and added -1 at the end but I got an error. Any suggestions?

    • @learnspreadsheets
      @learnspreadsheets  2 роки тому

      It’s definitely typing , -1 towards the end but the code is tricky so keep trying combinations & it should work or read the documentation on the Microsoft site for the functions

    • @TrekwithIslam
      @TrekwithIslam Рік тому +1

      Try this for end of previous month : = Date.EndOfMonth(Date.AddMonths(DateTime.Date(DateTime.LocalNow()),-1))