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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kerya
Frequent Visitor

Filter by Category and Date in Previous N Days

Hi all,

 

I am trying to filter a dataset by a category and previous 365 days in Power Query. As an example, I have 5 classes. Only two of them have to be re-taken yearly. So I want to filter out completions of Class 1 and Class 2 that are over 365 days old at the date of refresh.

 

I was able to find code for a static date, but I really need the date to be dynamic. Shown underlined here: 

Table.SelectRows(Source, each not List.Contains({"shoes","wallet","tie"},[Category]) or [Transaction Date] <= #date(2017, 1, 1))

 

Thank you!

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @kerya 

Here you go!


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel


c1234.PNGc123.PNGc12.PNGc1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @kerya ,


Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your problem.


Best Regards,
Stephen Tao

Nathaniel_C
Community Champion
Community Champion

Hi @kerya 

Here you go!


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel


c1234.PNGc123.PNGc12.PNGc1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Community Champion
Community Champion

Hi @kerya 
Try this:

if Duration.Days(Date.From (DateTime.LocalNow ()) -[Completion Date]) <365 and [Class]=1 or Duration.Days(Date.From (DateTime.LocalNow ()) -[Completion Date]) < 365 and[Class]=2 then 1 else 0

 

Then filter for 1.

 

Pictures  to follow.

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Community Champion
Community Champion

Hi @kerya 

Try this: a relative date filter.
Filter.PNG


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I really need to be able to do it in Power Query as a cleaning step on my raw data and on items only in those 2 specific categories. Thank you though!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.