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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
joew98
Frequent Visitor

Only show Last X days based on date slicer selection

Hi,

I have a filter to show data from (for example) the last 7 days. If I apply a date slicer to allow the user to go back and select a date 6 months ago (e.g. 11th January), how do I ensure that the relative date filter still applies so that the data only displays the last 7 days before 11th January?

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi, @joew98 

According to your description, you want to create two slicers in your visual . One is the Last N days and another is the selected Date.

Here are the steps you can refer to :
(1)This is my test data and we do not need to create any relationship between tables.

vyueyunzhmsft_0-1691726434613.png

And The Date in my side is created by this:

Date = CALENDAR(FIRSTDATE('Fact Table'[Date]) , LASTDATE('Fact Table'[Date]) )
 
(2)Then we can create  a Numeric range parameter as a "Last N days" slicer.
vyueyunzhmsft_1-1691726476572.pngvyueyunzhmsft_2-1691726513878.png

 

(3)Then we can create a measure like this:

Measure = var _days  = MAX('Last N Days'[Last N Days])
var _selected_date = MAX('Date'[Date])
return
IF( MAX('Fact Table'[Date]) <= _selected_date && MAX('Fact Table'[Date])>_selected_date -_days ,1,-1)
 
 
 
Then we can put the measure on the "Filter on this visual" and we can meet your need:
vyueyunzhmsft_3-1691726564582.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
joew98
Frequent Visitor

@v-yueyunzh-msft Hi thanks for the help. This solution works with table visuals but do you know how to get it to work for card visuals? When I apply the measure to 'Filters on this visual' for my card visuals, it does not allow me to select it. Do you know a workaround?

Hi , @joew98 

Thanks for your quick response ! If you want to put this in the card visual , you need to realize it in the dax .Like this:

Measure 2 = var _days  = MAX('Last N Days'[Last N Days])
var _selected_date = MAX('Date'[Date])
var t2 = FILTER('Fact Table' ,'Fact Table'[Date] <= _selected_date && 'Fact Table'[Date]>_selected_date -_days)
return
sumx(t2,[Value])

 

Then we can get it as the same :

vyueyunzhmsft_0-1692266909777.png

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi @v-yueyunzh-msft ,

 

I can't seem to get that to work for me, would you be able to help? I can add the measure to the card visual but cannot select it to change from 'is less than'. 

 

joew98_0-1692273513519.png

 

Hi , @joew98 

Thanks for your quick response! You can check if you may create any relationship :

vyueyunzhmsft_0-1692322865109.png

 

And you can also download the pbix file below.

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

v-yueyunzh-msft
Community Support
Community Support

Hi, @joew98 

According to your description, you want to create two slicers in your visual . One is the Last N days and another is the selected Date.

Here are the steps you can refer to :
(1)This is my test data and we do not need to create any relationship between tables.

vyueyunzhmsft_0-1691726434613.png

And The Date in my side is created by this:

Date = CALENDAR(FIRSTDATE('Fact Table'[Date]) , LASTDATE('Fact Table'[Date]) )
 
(2)Then we can create  a Numeric range parameter as a "Last N days" slicer.
vyueyunzhmsft_1-1691726476572.pngvyueyunzhmsft_2-1691726513878.png

 

(3)Then we can create a measure like this:

Measure = var _days  = MAX('Last N Days'[Last N Days])
var _selected_date = MAX('Date'[Date])
return
IF( MAX('Fact Table'[Date]) <= _selected_date && MAX('Fact Table'[Date])>_selected_date -_days ,1,-1)
 
 
 
Then we can put the measure on the "Filter on this visual" and we can meet your need:
vyueyunzhmsft_3-1691726564582.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.

Top Solution Authors
Top Kudoed Authors