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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
A_Fast_Panda
Frequent Visitor

How can I get selected columns to work in a legend?

You'll see in this example I have a SampleNumber that can contain 1 or more tests. The GoalGroup will always have the same repeating text per SampleNumber. When you do a count of GoalGroup, you'll get 12 as this is counting all of the tests. I however want 7 as that is how many GoalGroups there are per unique SampleNumber.  I was able to create a measure to count 1 GoalGroup per SampleNumber.

How can I go about getting these 5 goal groups to display correctly in a "100% Stacked column chart" within the "Legend" field? I'd like to be able to choose which column will be displayed via the "Category Field" column. I would like to do this without unpivoting the table as there are a million samples that are within my data and would not like to multiply my data by 5 causing it to go over my size limit. When I manually swap out Legend to GoalGroup_1 or GoalGroup_2 the data displays correctly in the chart.

I have data as follows:

A_Fast_Panda_0-1693919481318.png


Measure to count distinct GoalGroup per SampleNumber

A_Fast_Panda_1-1693919980026.png


The stacked column chart works when I manually change the legend. However, the Legend will not take measures, and from my understanding calculated columns only calculate upon data refresh so it won't work when passing the the distinct GoalGroup text per SampleNumber dynamically.

A_Fast_Panda_3-1693920550137.png

 

 

 

 

 

2 REPLIES 2
MFelix
Super User
Super User

Hi @A_Fast_Panda ,

 

Have you tried using the field parameters?

 

https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

 

This will allow for you to change the legend dinamically using the columns you need on your dataset.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelixThis seems to have worked great for the legend field. I'm assuming using my new measure below "GoalGroupSelectedParameter" instead of "Filter_GoalTAT" in my dynamic measure is the best way to go about getting Y-Axis counts per GoalGroup? If so, is there any way to have my field name be GoalGroup name dynamic so it's not just 1 general name?

GoalGroupSelectedParameter = VAR __SelectedValue =
    SELECTCOLUMNS (
        SUMMARIZE ( GoalGroupParameter, GoalGroupParameter[GoalGroupParameter], GoalGroupParameter[GoalGroupParameter Fields] ),
        GoalGroupParameter[GoalGroupParameter]
    )
RETURN IF ( COUNTROWS ( __SelectedValue ), __SelectedValue )

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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