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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Yashbaby
New Member

How do I get column header names as a slicer to change the legend dynamically?

Hi, I want to create a slicer with all the column header names, and when I select a column header name in the slicer, the visual/graph legend must change to that column values.

For example, let's take the below data which has column headers as Sales, Cost, Income, Region, and Year. 

Yashbaby_0-1626849388961.png

So, I want to create a slicer with all the header names (Sales, Cost, Income, Region, Year), and when I select a header name the legend needs to change to that header. For example, if I select 'Sales' in the slicer I need to get the below graph and the same way for 'Income, Region, Cost, Year' when I select 'Income, Region, Cost, Year' respectively in the slicer.  I tried looking for this solution, but I couldn't find it anywhere. Can someone please help me with this?

Yashbaby_1-1626849439616.png

 

 

2 ACCEPTED SOLUTIONS

Yes,that is obvious.

Tables would not be related.

You need to do that in one table only.

That is why I said that I am not sure about legend.

Check out https://community.powerbi.com/t5/Desktop/dynamic-legend-based-on-slicer-selection-possible/td-p/1228...

 

Regards,

Sanket Bhagwat

 

View solution in original post

Yashbaby
New Member

I found this youtube video helpful. Please find it here https://www.youtube.com/watch?v=8e8a3o1w51M&t=444s

View solution in original post

6 REPLIES 6
Yashbaby
New Member

I found this youtube video helpful. Please find it here https://www.youtube.com/watch?v=8e8a3o1w51M&t=444s

SanketBhagwat
Solution Sage
Solution Sage

Hi @Yashbaby .

I am not sure about legend, but you can achieve your desired result using unpivot.

However, the output screenshot you provided doesn't require any other feature.

It is a simple bar visual with Cost on Axis,Sales on Legend and Income on values.

 

I can help you with having column header names on the slicer.

 

 

 

Regards,

Sanket Bhagwat

 

Please confirm once what exact utput you need.

And if you want to have a slicer with column header names then follow the below steps.

1)Home->Transform Data.

2)Right click on column headers which you want in your slicer->Go to Transform->Unpivot Columns->Choose Unpivot Columns.

3)You will get 2 columns viz. Attribute and Value.

4)Home->Close and Apply.

5)Go to your report and drag a slicer onto your report page.

6)Add the 'attribute' field into the slicer.

7)Drag a bar and add value field into it.

 

You will get the output.

Do  let me know if that works.

 

If this post helps, then please mark it as 'Accept as Solution' so that others could find it easily.

Hi @SanketBhagwat,

 

Thank you for the answer. I duplicated the table and unpivoted it as you suggested for getting the slicer with header names, but both these tables are not connected. So, when I select the attribute filter the legend doesn't change. For example in the below figure, when I select 'Income', or 'Cost', or any other filter, the value doesn't change. What I need is for the legend to change to 'Income' when I select 'Income' in the slicer and to 'Cost' when I select the 'Cost'.  Hope my question is clear.

Yashbaby_0-1626854504196.png

Yashbaby_1-1626854647873.png

 

 

Yes,that is obvious.

Tables would not be related.

You need to do that in one table only.

That is why I said that I am not sure about legend.

Check out https://community.powerbi.com/t5/Desktop/dynamic-legend-based-on-slicer-selection-possible/td-p/1228...

 

Regards,

Sanket Bhagwat

 

wdx223_Daniel
Super User
Super User

you need unpivot your data firstly

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.