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

View all the Fabric Data Days sessions on demand. View schedule

Reply
chris1579
Advocate I
Advocate I

Toggle series in chart- legend remains

Hi,

I've got a measure added to a line chart wrapped in an IF that looks to a disconnected table to see if it's toggled ON, and if not it returns blank for the measure:

IF(

SELECTEDVALUE('Toggle'[Field]) = "On",
*measure stuff*,
BLANK()
)

As expected, if the toggle is OFF the line disappears from among the fields on the line graph. However, the legend remains at the top. Here it's toggled off and the green mark remains against the hidden Predicted Revenue line:
chris1579_0-1745570383295.png

Is there any way to get rid of this from the legend? I thought maybe something clever with field parameters but I can't work it out. I would rather avoid using bookmarks and (because I use implicit measure) calculation groups.

 

Thanks



 

 

1 ACCEPTED SOLUTION

for that follow the following steps 

 

create a toggle table

 

Toggle = DATATABLE(
    "Field", STRING,
    {
        {"On"},
        {"Off"}
    }
)

 

create a metrics parameter table 

 

Metric Parameter = 
{
    ("Sum Revenue", NAMEOF('Sales'[Revenue]), 0),
    ("Average Revenue", NAMEOF('Sales'[Revenue]), 1), 
    ("Predicted Revenue", NAMEOF('Sales'[Predicted Revenue]), 2)
}

 

create a measure 

 

Dynamic Metric = 
VAR SelectedMetric = SELECTEDVALUE('Metric Parameter'[Value1])
VAR ToggleState = SELECTEDVALUE('Toggle'[Field])
RETURN
    SWITCH(
        TRUE(),
        SelectedMetric = "Sum Revenue", SUM('Sales'[Revenue]),
        SelectedMetric = "Average Revenue" && ToggleState = "On", AVERAGE('Sales'[Revenue]),
        SelectedMetric = "Predicted Revenue" && ToggleState = "On", SUM('Sales'[Predicted Revenue]),
        BLANK()
    )

 

and use the values in the line chart, so now when you select ON you  can see 3 legend values , when you select off it will only show 1 legend value 

 

kushanNa_0-1745587013750.png

 

 

kushanNa_1-1745587043975.png

 

 

View solution in original post

7 REPLIES 7
v-sgandrathi
Community Support
Community Support

Hi @chris1579 ,

 

Has your issue been resolved?If the response provided by @kushanNa (Thank you for the answer) addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

If yes, kindly accept the useful reply as a solution and give us Kudos. It would be appreciated.

 

Thank you for your understanding!

kushanNa
Super User
Super User

Hi @chris1579 

 

you need something like this ? 

kushanNa_0-1745571801382.png

 

this how i achived this 

 

create a slicer table 

 

CalcType = DATATABLE(
    "Metric", STRING,
    {
        {"Sum"},
        {"Average"}
    }
)

create a mesure

 

Dynamic Revenue = 
VAR SelectedCalc = SELECTEDVALUE('CalcType'[Metric])
RETURN
SWITCH(
    SelectedCalc,
    "Sum", SUM('Sales'[Revenue]),
    "Average", AVERAGE('Sales'[Revenue]),
    BLANK()
)

include these values in the line chart and slicer

 

kushanNa_1-1745571943092.png

 

 

Thanks- how would this work if I want to have a slicer that only denotes (say) ON/OFF for the one measure? I don't need to be able to swap out the other fields in the visual.

In other words for the Switch I'd need it to return 2 fields for OFF and 3 for ON, instead of how it is in your example with one field per option.

 

for that follow the following steps 

 

create a toggle table

 

Toggle = DATATABLE(
    "Field", STRING,
    {
        {"On"},
        {"Off"}
    }
)

 

create a metrics parameter table 

 

Metric Parameter = 
{
    ("Sum Revenue", NAMEOF('Sales'[Revenue]), 0),
    ("Average Revenue", NAMEOF('Sales'[Revenue]), 1), 
    ("Predicted Revenue", NAMEOF('Sales'[Predicted Revenue]), 2)
}

 

create a measure 

 

Dynamic Metric = 
VAR SelectedMetric = SELECTEDVALUE('Metric Parameter'[Value1])
VAR ToggleState = SELECTEDVALUE('Toggle'[Field])
RETURN
    SWITCH(
        TRUE(),
        SelectedMetric = "Sum Revenue", SUM('Sales'[Revenue]),
        SelectedMetric = "Average Revenue" && ToggleState = "On", AVERAGE('Sales'[Revenue]),
        SelectedMetric = "Predicted Revenue" && ToggleState = "On", SUM('Sales'[Predicted Revenue]),
        BLANK()
    )

 

and use the values in the line chart, so now when you select ON you  can see 3 legend values , when you select off it will only show 1 legend value 

 

kushanNa_0-1745587013750.png

 

 

kushanNa_1-1745587043975.png

 

 

Hi,

 

For clarity, what does Value1 refer to in your example?

I tried this and got a composite key error, so i switched the SelectedMetric function from SelectedValue to Max and it's not displaying properly at all. Wonder if I'm using the wrong field though.

Value1 is the first column of the parameter table ,

 

you can find the sample pbix file in here : https://filebin.net/cx6khb8b62d55pj4 

Ah ok - I had the Metric Parameter table set up as a Field Parameter; i've now changed it to a simple table as in your example (and changed back from Max to SelectedValue) and it works. Many thanks.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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