Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello everyone!
I have a date column that I would like to filter on all dates 7 Days before today.
Is there any chance to determine that with Power Query?
Solved! Go to Solution.
Hi @joshua1990 ,
You could try below M code
let
Source = List.Dates(#date(2020,4,12), 30,#duration(1,0,0,0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each if [Column1]<=DateTime.Date(DateTime.LocalNow())-#duration(7,0,0,0) then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1))
in
#"Filtered Rows"
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @joshua1990 ,
You could try below M code
let
Source = List.Dates(#date(2020,4,12), 30,#duration(1,0,0,0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each if [Column1]<=DateTime.Date(DateTime.LocalNow())-#duration(7,0,0,0) then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1))
in
#"Filtered Rows"
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Yes, it is DateTime.LocalNow I believe. https://www.powerquery.io/date-time/datetime.localnow
Hi @joshua1990
You can do it in the Model using Slicer or Filter
https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range
Or you can use Relative Date Dimension
https://community.powerbi.com/t5/Community-Blog/Relative-Date-Dimension/ba-p/779039
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
24 | |
12 | |
11 | |
11 | |
8 |
User | Count |
---|---|
43 | |
25 | |
15 | |
14 | |
12 |