Forum Discussion
Relative Date Filters for Last Days
- 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 falsePaste 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.
So I am new to DAX and M but I follow what you are suggesting. For the M code chunk would I ever need to change
Source = {Number.From(#date(2020,3,1))..Number.From(#date(2020,4,30))}
Yes. That was just an arbitrary date range of March 1 through April 30 I used for this example. You can put in whatever date range you want, or better yet, make this date range fully dynamic so it moves along with the dates added to your model. See this article for instructions on that: Creating a Dynamic Date Table in Power Query
That is how I do all of my date tables in Power BI.