Forum Discussion
How to write DAX code that will dynamically group the bottom 20% of results for a Pie Chart?
- 2 years ago
So I am NGL, I got a little lost trying to understand how to translate the article to suit my needs for a pie chart and percentages, but generally it seemed on point so I gave you a thumbs up. I'm almost ashamed to say...I went and asked ChatGPT a few questions and got a working solution for my situation. Edited for posting, here it is for posterity:
(1) Created a measure that counts my reported conditions:CondCalc = CALCULATE(COUNTROWS('Table'), ALLEXCEPT('Table', 'Table'[Condition]))(2) Created calculated column to use in my pie chart:ConditionGroupBottom20 =VAR Threshold = PERCENTILEX.INC('Table', [CondCalc], 0.2)RETURNIF([CondCalc] >= Threshold,'Table'[Condition],"Others")
(3) Assigned the calculated column as the value/legend of my pie chart.This had the effect of grouping the bottom 20% of my pie chart slices into one categor "Others" while leaving the remaining slices with full details/name.
"M Code" and "dynamically" do not go together. You will have to do this in DAX.
Here is a walkthrough of what is required. Buckle up, it is not a simple ride.
So I am NGL, I got a little lost trying to understand how to translate the article to suit my needs for a pie chart and percentages, but generally it seemed on point so I gave you a thumbs up. I'm almost ashamed to say...I went and asked ChatGPT a few questions and got a working solution for my situation. Edited for posting, here it is for posterity:
(1) Created a measure that counts my reported conditions:
(3) Assigned the calculated column as the value/legend of my pie chart.
This had the effect of grouping the bottom 20% of my pie chart slices into one categor "Others" while leaving the remaining slices with full details/name.
- lbendlin2 years agoSuper User
That's actually cute, a nice way to abuse PERCENTILEX. You can mark your post as the solution.