Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Relative Date Filters for Last Days

I looked for some information on this but was not able to find anything and in an effort to save some time I figured I would ask here. I am working on a report where the source data is updated daily ...
  • edhans's avatar
    6 years ago

    I've run into enough minor or major issues with the relative date filtering, I've abandoned. it. I add a field to my Date Table in Power Query to give me a true or false. In your case, it would be:

     

    = if Date.AddDays(
        DateTime.Date(
            DateTime.LocalNow()
            )
            ,-1) = [Date]
    then true else false

     

    Paste this entire section into a new Blank Query in Power Query in the Advanced editor and you'll see it. It will only show true for yesterday.

     

    let
        Source = {Number.From(#date(2020,3,1))..Number.From(#date(2020,4,30))},
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
        #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Date.AddDays(
        DateTime.Date(
            DateTime.LocalNow()
            )
            ,-1) = [Date]
    then true else false)
    in
        #"Added Custom"

     

     Only yesterday should show TRUE. Drop that in your filter and every refresh, it will update.