Forum Discussion

Phoen1x09's avatar
Phoen1x09
Frequent Visitor
2 years ago
Solved

How to write DAX code that will dynamically group the bottom 20% of results for a Pie Chart?

I have a Pie Chart showing the percent/value breakdown of reported conditions from a customer. There are roughly 20 or so categories, with the bottom 8 or so being small amounts that comprise 20% of ...
  • Phoen1x09's avatar
    Phoen1x09
    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)
    RETURN
    IF(
        [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.