Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tharris
Frequent Visitor

Advanced Editor - Date Filter to include last 2 months, today, and all future or next 5 years

Hello Community,

 

I have been trying to filter my dataset as the parameters above.

 

I can set it up to give me the last 2 months plus the next 5 years, but that excludes today.

 

#"Filtered Rows" = Table.SelectRows(#"Renamed Columns3", each Date.IsInPreviousNMonths([Date], 2) or Date.IsInNextNYears([Date], 5)),

 

I can also set it up where it will give me the last 2 months, and all future from a specific date, which I can selet today, but the problem here is as the future comes, this will be completely wrong since it is a hard coded date.

 

#"Filtered Rows" = Table.SelectRows(#"Changed Type1", each Date.IsInPreviousNMonths([Date], 2) or [Date] >= #date(2020, 4, 17)),

 

Lastly, I have also tried to combine both by doing a manual edit in Advanced editor as below, but this does not work as Date is in Previous and Date is in the Next only work in Basic filtering, and that doesn't allow me to add today.

 

#"Filtered Rows" = Table.SelectRows(#"Changed Type1", each Date.IsInPreviousNMonths([Date], 2) or Date.IsInCurrentDay([Date]) or Date.IsInNextNYears([Date],5)),

 

What I am thinking is that I need to use option 2, but replace the hard coded date with a function, but haven't been able to find a function that will work here.

 

Please help!

Thanks!

1 ACCEPTED SOLUTION

Yes, I am aware of that @edhans . I am working on modeling.

 

I figured out a solution that works.

 

= Table.SelectRows(#"Changed Type1", each Date.IsInPreviousNDays([Date], 60) or [Date] >= Date.From(Date.StartOfMonth(DateTime.LocalNow())))

 

 

View solution in original post

3 REPLIES 3
edhans
Super User
Super User

Use DateTime.Date(DateTime.LocalNow())

 

That is the Power Query equivalent to TODAY() in Excel.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Yes, I am aware of that @edhans . I am working on modeling.

 

I figured out a solution that works.

 

= Table.SelectRows(#"Changed Type1", each Date.IsInPreviousNDays([Date], 60) or [Date] >= Date.From(Date.StartOfMonth(DateTime.LocalNow())))

 

 

Sorry I misunderstood your request. I thought this was your question.

"What I am thinking is that I need to use option 2, but replace the hard coded date with a function, but haven't been able to find a function that will work here."

I was replacing the hardcoded date with a function.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors