Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How to conditionally display line graph data based on date range selection?

Hi Power BI community, i am encountering an issue with a line graph visualization in Power BI and need some guidance. My objective is to display data in the line graph only if the user's date range selection via a date slicer does not exceed 14 days. For selections over 14 days, the graph should not display any data.

 

Here are the steps and DAX measures i implemented:

1. Calculate Minimum and Maximum Dates selected by User:

 

MinDateSelected = MIN(Data[Date])
MaxDateSelected = MAX(Data[Date])

 

2. Determine the daterange:

Using these measures, i calculated the date range selected:

 

DateRange = DATEDIFF([MinDateSelected],[MaxDateSelected],DAY) + 1

 

3. Conditional measure for displaying the data:

Next, i created a measure intended to conditionally display data based on the date range:

 

 

DisplayData = IF([DateRange] <=14,1,BLANK())

 

 

The DisplayData measure performs as expected within a card visual, showing 1 when the selection is within 14 days, and displaying blank for selections that exceed 14 days.

 

However, when applying this measure as a visual-level filter on the line graph (set to show items when the value is 1), the graph continue to display all data points, regardless of the selected date range.

On Y axis, the field of Start Time refers to DateTime format (e.g. 2/6/2024 11:05:08).

Has anyone faced a similar challenge or can offer adviceon how to ensure the line graph adheres to this conditional display based on the date range selected?

 

Thank you!

  • Anonymous,

     

    Try using ALLSELECTED to get the slicer dates.

     

    MinDateSelected = MINX ( ALLSELECTED ( Data ), Data[Date] )
    MaxDateSelected = MAXX ( ALLSELECTED ( Data ), Data[Date] )

     

2 Replies

  • Anonymous,

     

    Try using ALLSELECTED to get the slicer dates.

     

    MinDateSelected = MINX ( ALLSELECTED ( Data ), Data[Date] )
    MaxDateSelected = MAXX ( ALLSELECTED ( Data ), Data[Date] )