Forum Discussion
Power BI : Dynamic Colors for TopN values on Clutered Column Chart
- 3 years ago
shout-out to Amira Bedhiafi for providing the solution on stackoverflow
Below is the DAX solution to the problem in the [SelectedSubcategoryColor] measureSelectedSubcategoryColor = VAR _CurrentSubcategory = SELECTEDVALUE ( Subcategory[SubcategoryName] ) VAR _AllSubcategories = ALLSELECTED( Subcategory ) VAR _CurrentRank = RANKX( _AllSubcategories, [Sales], , DESC ) RETURN SWITCH( TRUE(), _CurrentRank = 1, "Red", _CurrentRank = 2, "Green", _CurrentRank = 3, "Blue", _CurrentRank = 4, "Orange", _CurrentRank = 5, "Purple", _CurrentRank = 6, "Yellow", _CurrentSubcategory = "Others", "Grey", "Black" )
Vickar As per your problem statement , you are trying to select less than 6 , when it has to be static what is the purpose of reducing the number of elements.
The example which I shared is working with all slicer values even when I select 1 it shows 1 value + others
https://drive.google.com/file/d/1CaSISzxacCwRldbqx7PLo1nyckrprPXk/view?usp=sharing
- Vickar3 years ago
Advocate II
the requirement is to show max 7 data elements on the visual if more than 6 subcategories are selected ( 6 topn and rest as others )
And it is a valid use case that the user can select less than 6 subcategories. the issue is not with [TopNSubcategorySales] measure. it is working fine for all scenarios. the issue is with the [SelectedSubcategoryColor] measure that assigns colors dynamically to the subcategories on the visual. this measure is breaking the visual if less than 5 subcategories are selected. I hope the issue is clearer now. Appreciate your efforts and support. And I double checked your solution, the visual is still breaking if I select less values in hte filter pane.