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

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.

weiwah_0-1710140398730.png

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!

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@weiwah,

 

Try using ALLSELECTED to get the slicer dates.

 

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

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
weiwah
Frequent Visitor

@DataInsights It works! Thank you!

DataInsights
Super User
Super User

@weiwah,

 

Try using ALLSELECTED to get the slicer dates.

 

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

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.