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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ragnezza
Frequent Visitor

Date Range based on Slicer selection

Hello - I'm looking to return a list of the previous "X" days based on a selected day from a slicer.

 

For example, once a day is selected in the 'Date' slicer, I want to return the date range in the visualization for the previous 180 days up to the selected day.

 

Dynamic Dates.PNG

 

In simple words, the logic would be something like the below, but I cannot make it work:
IF ( Date >= SELECTEDVALUE ( Date )-180 || Date <= SELECTEDVALUE ( Date ) , Date , blank() ) 

And then use 'Date' in the visualization and exclude blanks.

Any recommendation is more than welcome, thanks!!

1 ACCEPTED SOLUTION

Thanks @DataNinja777 . This can work if I want to have the cumulative "Daily Trends" up to the selected day.
For this purpose I find this other solution:

Measure =
if( MAX( 'Main_Table'[Date]) >= SELECTEDVALUE('Date'[Date],min('Date'[Date]) )-180 &&
MAX( 'Main_Table'[Date]) <= SELECTEDVALUE('Date'[Date],max('Date'[Date]) ),
"Yes", "No" )

 

And then use this 'Measure' as a filter in the visualization.

View solution in original post

6 REPLIES 6
ragnezza
Frequent Visitor

Thanks @DataNinja777 . Your solutions provided a cumulative count for the last "X" days, while I was looking to include/exclude days based on the selection. I made it work with the following Measure and by adding a separate Table with just the 'Date' field, which is used as filter.

Measure_last_180_days = 

IF (SELECTEDVALUE('Date'[Date])-180 <= MAX( 'Main Table'[Date]) &&
SELECTEDVALUE('Date'[Date]) >= MAX('Main Table'[Date]),"yes","no" )
ragnezza
Frequent Visitor

Thanks @DataNinja777 , this can help as it outputs the [Daily trends] for the previous 180 days, but it doesn't have any relation with the SELECTEDVALUE.
Below are two examples of how I would like this visualization to show based on the selected dates:
Dynamic Dates1.PNG

 

Dynamic Dates2.PNG

thanks! 

Hi @ragnezza ,

What about like below?

 

Sakiko_0-1694031697377.png

 

Thanks @DataNinja777 . This can work if I want to have the cumulative "Daily Trends" up to the selected day.
For this purpose I find this other solution:

Measure =
if( MAX( 'Main_Table'[Date]) >= SELECTEDVALUE('Date'[Date],min('Date'[Date]) )-180 &&
MAX( 'Main_Table'[Date]) <= SELECTEDVALUE('Date'[Date],max('Date'[Date]) ),
"Yes", "No" )

 

And then use this 'Measure' as a filter in the visualization.

Hi  @ragnezza ,

It seems that you have gotten a solution. Could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

Best Regards    

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
DataNinja777
Super User
Super User

Hi @ragnezza,

What about using DATESINPERIOD function?

DATESINPERIOD function (DAX) - DAX | Microsoft Learn

Something like below is how it can be used:

Sakiko_0-1693952560904.png

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.