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
0Experience
Helper III
Helper III

Showing Only Total Labels for Stacked Bar Chart with Conditional DAX Logic

Hello,

 

If I select single selection from slicer (type-1/type-2/type-3) then need to see the data value like below. 

 

0Experience_0-1755782143651.png

 

If I select single selection from slicer (type-12 only) which is a stacked chart, combination of type-1 and type-2. 

 

0Experience_1-1755782246132.png

 

If I select multiple selection from slicer then no individual data label will come (will show only total). 

 

0Experience_2-1755782341850.png

 

I'm currently using a DAX measure in Power BI to hide data labels when selecting type-1 and type-2 (at the same time) from a slicer. But, it is not working. It is showing (individual data labels, and total data labels both)

 

Data Label = 
VAR SelectedCategories = VALUES(type_sort[type])  -- Get all selected categories
VAR ConcatenatedSelection = CONCATENATEX(SelectedCategories, [type], ", ")

RETURN
IF(
    ConcatenatedSelection = "type-1, type-2",
    "",  -- Hide the data label
    [describeMeasure]  -- Otherwise, show the data label
)

 

As I mentioned before, I need to turn on total labels on to see the total for the type-12 (when selecting it only). I also need to turned on the data labels to see data point when selecting a single selection of type-1/type-2/type-3.

 

If anyone has suggestions for improving the DAX or alternative approaches to achieve this behavior, I’d really appreciate it.

 

You can find the Power BI file here: [link]

 

1 ACCEPTED SOLUTION
0Experience
Helper III
Helper III

The code works fine when I kept both Data Labels and Total Labels turned on.

 

Data_Label = 
VAR SelectedTypes = ALLSELECTED(type_sort[type])
VAR SelectedCount = COUNTROWS(SelectedTypes)

RETURN
IF(
    SelectedCount = 1 &&
    MAX(type_sort[type]) IN { "type-1", "type-2", "type-3" },
    [describeMeasure],
    BLANK()
)

 

If I select only type-1

0Experience_0-1755875480691.png

 

If I select combination of type-1/type-2/type-3

0Experience_1-1755875554024.png

 

If I select only type-12

0Experience_2-1755875603227.png

 

If I select any combination of type-1/type-2/type-3/type-12

 

0Experience_3-1755875660145.png

 

Note: While ChatGPT provided the final working code, I had already shared the initial code, expected output, and other relevant details. It took a few iterations to get everything functioning correctly.

 

Thanks to everyone who engaged with my post and offered helpful suggestions, your input was truly appreciated!

View solution in original post

7 REPLIES 7
0Experience
Helper III
Helper III

The code works fine when I kept both Data Labels and Total Labels turned on.

 

Data_Label = 
VAR SelectedTypes = ALLSELECTED(type_sort[type])
VAR SelectedCount = COUNTROWS(SelectedTypes)

RETURN
IF(
    SelectedCount = 1 &&
    MAX(type_sort[type]) IN { "type-1", "type-2", "type-3" },
    [describeMeasure],
    BLANK()
)

 

If I select only type-1

0Experience_0-1755875480691.png

 

If I select combination of type-1/type-2/type-3

0Experience_1-1755875554024.png

 

If I select only type-12

0Experience_2-1755875603227.png

 

If I select any combination of type-1/type-2/type-3/type-12

 

0Experience_3-1755875660145.png

 

Note: While ChatGPT provided the final working code, I had already shared the initial code, expected output, and other relevant details. It took a few iterations to get everything functioning correctly.

 

Thanks to everyone who engaged with my post and offered helpful suggestions, your input was truly appreciated!

Greg_Deckler
Community Champion
Community Champion

@0Experience Is there a particular reason your relationship is not active? You should be able to solve this with conditional formatting for your Data Label values.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler thanks Greg. If I make the relationship active then I can not see type-12 in my visual (if I select it from slicer).

@0Experience The way you have this configured I don't think it is actually possible. The reason is that you want the label to be visible and invisible under technically the same conditions. I realize that this might not sound correct but create two measures like so:

Measure 1 = COUNTROWS( 'Test_Data_Table' )

Measure 2 = COUNTROWS( 'type_sort' )

Use each of those in turn for you data labels and you'll see what I mean.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler  You're probably right, it might not be possible to display this.

 

I tried your suggested methods. While Measure 2 correctly shows a count of 4 when I select four types from the slicer, the visual still displays only 1 (it make sense too).

 

I also applied a condition like “if Measure 2 > 2, then hide data labels,” but unfortunately, it didn’t.

0Experience_0-1755789444733.png

 

Still, I really appreciate your time and thoughtful suggestions.

 

 

Thank you!

Hi @0Experience,

(again) 🙂

 

I might have made it, the file is here, can you check this satisfies your requirements? The only thing that seems to me impossible is to hide the labels if you select multiple items differently than type1 and type-12

 

https://drive.google.com/drive/folders/14HuWjOKld9A5x-oHacplyMRa6J5rNyjd?usp=sharing

 

Hope I helped

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

@FBergamaschiThank you so much for your time, your help, and the code you shared, I truly appreciate it.

 

It was good to see that the code worked partially. However, when I applied it to my actual dashboard, it unfortunately didn’t behave as expected (even for Type-12 and type-1) too. The data labels are still showing for every combination.

 

Still, I’m really grateful for your support and suggestions.

 

Thanks again!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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