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
RedHare
Frequent Visitor

How to filter dates between a certain number of days?

I have a table that includes a date column. I need to split this table into 3 seperate tables which filter that date column between dates that occured in the past 0-30, 31-60, and 61-90 days. 
Initially I was thinking of using the Date.IsInPreviousNDays function, but how can I say is in the previous 31-60 days?

 

Thanks!

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

I am presuming you want a PQ solution as you have posted in PQ forum and you talked about Date.IsInPreviousNDays.

Below are the formulas for these in PQ which will help you to apply required filter

For within 30 days
= Date.IsInPreviousNDays([Date],30)

For 31-60 days bin
= Date.IsInPreviousNDays([Date],60) and not Date.IsInPreviousNDays([Date],30)

For 61-90 days bin
= Date.IsInPreviousNDays([Date],90) and not Date.IsInPreviousNDays([Date],60)

 

View solution in original post

4 REPLIES 4
mahenkj2
Solution Sage
Solution Sage

Hello@RedHare 

 

As @speedramps suggested, better to add transformation in the date table and relate that table with the fact table.

mahenkj2_0-1652026277192.png

 

You can add a custom column to count days from today:

mahenkj2_1-1652026348866.png

 

Then add a conditional column to categorize the datefilter:

mahenkj2_2-1652026406004.png

 

The date table used is not the proper one, just created a short sample.

 

Please see the sample file on link below:

https://drive.google.com/drive/folders/1JjSs9JRF2WPjlLHHCOoV5kzij4zqUzhw?usp=sharing

 

Vijay_A_Verma
Super User
Super User

I am presuming you want a PQ solution as you have posted in PQ forum and you talked about Date.IsInPreviousNDays.

Below are the formulas for these in PQ which will help you to apply required filter

For within 30 days
= Date.IsInPreviousNDays([Date],30)

For 31-60 days bin
= Date.IsInPreviousNDays([Date],60) and not Date.IsInPreviousNDays([Date],30)

For 61-90 days bin
= Date.IsInPreviousNDays([Date],90) and not Date.IsInPreviousNDays([Date],60)

 

Thank you, this is exactly what I needed.

speedramps
Super User
Super User

Hi RedHare

 

It is bad praticve to build your own date logic,

Always use calenedar table for date logic.

Build and test it once and use it always !

Then you can slice and subtotal by date, week, month and year age.

 

You dont have to split the tables, unless you want to.

You could have all the dates in one fact table with a calendar filter to produce 3 reports.

Click here to watch video 

 

Please click the thumbs up and accept as solution buttons

 

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