Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
hwong
Advocate I
Advocate I

Cumulative % by category for pareto

I am trying to create a pareto chart using the column and line chart but am running into an issue trying to calculate the cumulative % that is required in a pareto.

 

I have 2 tables, Tests and Test Anomalies linked by Test ID:

hwong_0-1624906580785.png

 

Given the following data, I would like to see results below when sorting the results by the count of failures per anomaly type:

Tests

Test IDOperatorResultDate
1ABCPassSunday, June 27, 2021
2ABCFailSunday, June 27, 2021
3XYZPassSunday, June 27, 2021
4XYZFailSunday, June 27, 2021
5ABCFailSunday, June 27, 2021
6XYZPassMonday, June 28, 2021
7XYZFailMonday, June 28, 2021
8ABCPassMonday, June 28, 2021
9ABCFailMonday, June 28, 2021
10XYZFailMonday, June 28, 2021

 

Test Anomalies

Test IDAnomaly
2C
2B
4A
5C
7B
9C
9B
10C
10B
10A

 

Expected Result

AnomalyCount of Anomaly (sort DESC by this column)Cumulative %
B440%
C480%
A2100%

 

How can I calculate the Cumulative % in this scenario?

 

P.S. I have read articles and seen other answers where there is a sortable column of pre-calculated values for calculating cumulative %, but in this case there is no sort column because the Count of Anomaly will be dynamic based on filter selection. For example, the user can filter by Date and that would change the sort order.

 

Sample PBIX can be downloaded here:

https://1drv.ms/u/s!Arsjvofj3uEZh8sJnGi8OVry7dWAQw?e=vgZzZv 

1 ACCEPTED SOLUTION

Anyway, I figured it out using some temporary tables to get the "sort column". It was a lot more involved than I had anticipated. Here's the solution I ended up with:

Cumulative % = 
    VAR countSummaryTable =
        CALCULATETABLE(
            SUMMARIZE(
                'Test Anomalies',
                'Test Anomalies'[Anomaly],
                "Anomaly Count", COUNT('Test Anomalies'[Anomaly])
            ),
            REMOVEFILTERS('Test Anomalies'[Anomaly])
        )
    VAR rankedSummaryTable =
        ADDCOLUMNS(
            countSummaryTable,
            "Anomaly Count Rank", RANKX(countSummaryTable, 
                                    RANKX(countSummaryTable, [Anomaly Count] + DIVIDE(
                                                                                RANKX(countSummaryTable, [Anomaly]),
                                                                                COUNTROWS(countSummaryTable) + 1)
                                    ), ,ASC,Dense))
    VAR selectedAnomalyRank = MAXX(FILTER(rankedSummaryTable, [Anomaly]=SELECTEDVALUE('Test Anomalies'[Anomaly])), [Anomaly Count Rank])
    VAR totalAnomalies = SUMX(countSummaryTable, [Anomaly Count])
    RETURN        
        DIVIDE(
            SUMX(
                FILTER(rankedSummaryTable, [Anomaly Count Rank] <= selectedAnomalyRank),
                [Anomaly Count]
            ),
            totalAnomalies
        )

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Any reason why Anomaly is in the order of B,C,A and not C,B,A when Both B and C have the same count?  Also, for this specific question, what is the use of the Tests table.  For your expected, all we need is the Test Anomalies Table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

 

In case of a tie (in this case B and C have the same count), it doesn't matter what order the Anomalies show up in. It just turns out that Power BI column chart and table showed it in the B,C,A order when I put the data in a visual and sorted it by the anomaly count.

 

The reason for the Tests table is because I want to filter by date. In the example data, filtering to show only Monday vs Sunday should result in a different ordering. For Sunday only, the pareto ordering becomes "C, A, B", and for Monday only, the pareto ordering becomes "B, C, A".

 

Thanks,

Hubert

v-yingjl
Community Support
Community Support

Hi @hwong ,

To calculate the running total value, you must need to have a 'sorted column'. 

Based on your report, since you use the date column to filter, so needs another 'sorted column' to calculate the running total value.

 

Refer: Dynamically Calculate A Power BI Running Total Or Cumulative Total 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

I need to sort by the count of the anomalies, which must be dynamic to account for filters and slicers. This is why I don't know what to use for a "sort column". The sort order is not known until the visual is presented and filters/slicers are accounted for.

 

Thanks,

Hubert

Anyway, I figured it out using some temporary tables to get the "sort column". It was a lot more involved than I had anticipated. Here's the solution I ended up with:

Cumulative % = 
    VAR countSummaryTable =
        CALCULATETABLE(
            SUMMARIZE(
                'Test Anomalies',
                'Test Anomalies'[Anomaly],
                "Anomaly Count", COUNT('Test Anomalies'[Anomaly])
            ),
            REMOVEFILTERS('Test Anomalies'[Anomaly])
        )
    VAR rankedSummaryTable =
        ADDCOLUMNS(
            countSummaryTable,
            "Anomaly Count Rank", RANKX(countSummaryTable, 
                                    RANKX(countSummaryTable, [Anomaly Count] + DIVIDE(
                                                                                RANKX(countSummaryTable, [Anomaly]),
                                                                                COUNTROWS(countSummaryTable) + 1)
                                    ), ,ASC,Dense))
    VAR selectedAnomalyRank = MAXX(FILTER(rankedSummaryTable, [Anomaly]=SELECTEDVALUE('Test Anomalies'[Anomaly])), [Anomaly Count Rank])
    VAR totalAnomalies = SUMX(countSummaryTable, [Anomaly Count])
    RETURN        
        DIVIDE(
            SUMX(
                FILTER(rankedSummaryTable, [Anomaly Count Rank] <= selectedAnomalyRank),
                [Anomaly Count]
            ),
            totalAnomalies
        )

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.