Forum Discussion
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.
If I select single selection from slicer (type-12 only) which is a stacked chart, combination of type-1 and type-2.
If I select multiple selection from slicer then no individual data label will come (will show only total).
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]
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
If I select combination of type-1/type-2/type-3
If I select only type-12
If I select any combination of type-1/type-2/type-3/type-12
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!
7 Replies
- Greg_Deckler
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.
- 0Experience
Helper III
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).
- Greg_Deckler
Community Champion
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.
- 0Experience
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
If I select combination of type-1/type-2/type-3
If I select only type-12
If I select any combination of type-1/type-2/type-3/type-12
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!