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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
laciodrom_80
Helper IV
Helper IV

Reference lines on demand

Hi,

 

I've got a report with a line chart, I wish add to my report a reference line on demand: in particular I'd like to have a filter which specifies some reference lines (max - min - mean, etc.) so that when user clicks one of these the relative reference line is displayed into the chart, is it possible? 

 

Thanks in advance for any hint!

 

 

Luca
1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

hi @laciodrom_80

 

First create a table with a column with Max, Min , Average ...Use this to show a slicer to select the calculate formula of the line.

 

Next, create a measure to calc accord to slicer selected.

 

 

LineCalc =
IF (
    VALUES ( Table1[Value] ) <> BLANK (),
    IF (
        HASONEVALUE ( Table2[LineType] ),
        SWITCH (
            VALUES ( Table2[LineType] ),
            "Max", CALCULATE ( MAX ( Table1[Value] ), ALLSELECTED ( Table1 ) ),
            "Min", CALCULATE ( MIN ( Table1[Value] ), ALLSELECTED ( Table1 ) ),
            "Average", CALCULATE ( AVERAGE ( Table1[Value] ),ALLSELECTED ( Table1 ) )
        )
    ),
    BLANK ()
)

 




Lima - Peru

View solution in original post

8 REPLIES 8
v-haibl-msft
Employee
Employee

@laciodrom_80

 

Vvelarde’s solution should be correct. You can also try to use the Min/Max/Average Line in analytics pane as below.

Reference lines on demand_1.jpg

 

Best Regards,

Herbert

 

@v-haibl-msft unfortunatelly reference lines can't be shown/hidden on demand with this solution Smiley Sad

Luca
Vvelarde
Community Champion
Community Champion

hi @laciodrom_80

 

First create a table with a column with Max, Min , Average ...Use this to show a slicer to select the calculate formula of the line.

 

Next, create a measure to calc accord to slicer selected.

 

 

LineCalc =
IF (
    VALUES ( Table1[Value] ) <> BLANK (),
    IF (
        HASONEVALUE ( Table2[LineType] ),
        SWITCH (
            VALUES ( Table2[LineType] ),
            "Max", CALCULATE ( MAX ( Table1[Value] ), ALLSELECTED ( Table1 ) ),
            "Min", CALCULATE ( MIN ( Table1[Value] ), ALLSELECTED ( Table1 ) ),
            "Average", CALCULATE ( AVERAGE ( Table1[Value] ),ALLSELECTED ( Table1 ) )
        )
    ),
    BLANK ()
)

 




Lima - Peru

Hi  @Vvelarde,

 

thanks for your suggestion, only twoclarification:

 

How are related the slicer selection and the LineCalc measure? Does Table2[LineType] in switch statement represent the current selection in the slicer?

 

How can I add the LineCalc measure to my chart?

 

Here my chart without reference lines

chart.pngtool.png

 

I should add LineCalc measure to "Valori" field (Spot Series Values is the measure which draws the chart lines), but if I drag and drop LineCalc measure to "Valori" field it overwrites Spot Series Values Smiley Frustrated

 

 Thanks a lot!

Luca

@laciodrom_80

 

Just upload a simple .pbix file here for reference which follow the solution provided by Vvelarde.

If you have legend in your line chart, as Vvelarde said, you cannot have more than one value in the Values field now. Please vote this idea here.

 

Best Regards,

Herbert

Thanks guys!

 

@v-haibl-msft  idea just voted!  Smiley Wink

Luca

@laciodrom_80

 

How are related the slicer selection and the LineCalc measure? Does Table2[LineType] in switch statement represent the current selection in the slicer?

 

Yes. able2[LineType] represent the current selection in slicer. The slicer is the column of tha table with the line types.

 

How can I add the LineCalc measure to my chart?

 

If you have a legend this doesnt' work. When you use a legenf only Works with 1 line. 

 




Lima - Peru
Greg_Deckler
Super User
Super User

Not to my knowledge.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.