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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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
v-stephen-msft
Community Support
Community Support

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
Super User
Super User

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
Super User
Super User

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
Super User
Super User

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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