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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Yiyi
Helper I
Helper I

The running total doesn't count same values? Why :(

Hello all, 

 

I am new to DAX and I tried to calculate the running total for the variable of media so I can see how many media counts for 80% of all the item creation. The result is problematic as the rows with the same values were not cumulated: 

Yiyi_0-1690877167714.png

My Dax is as follows: 

Pareto =
VAR Total_Unique_Item =
   CALCULATE(
   DISTINCTCOUNT(Data[HeadlineID]),
   ALLSELECTED(Data)
    )
VAR Current_Total_Unique_Item = DISTINCTCOUNT(Data[HeadlineID])
VAR SummarizedTable =
   SUMMARIZE(
   ALLSELECTED(Data),
   Data[Media],
   "Unique_Item_Count", DISTINCTCOUNT(Data[HeadlineID])
)
VAR CumulativeSum =
   SUMX (
   FILTER(SummarizedTable, [Unique_Item_Count] >= Current_Total_Unique_Item),
   [Unique_Item_Count])
RETURN
CumulativeSum/Total_Unique_Item

 

I really appreciate if you could help! Thanks! 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Yiyi ,

 

I suggest you to try code as below to create a measure.

Pareto =
VAR Total_Unique_Item =
    CALCULATE ( DISTINCTCOUNT ( Data[HeadlineID] ), ALLSELECTED ( Data ) )
VAR Current_Total_Unique_Item =
    DISTINCTCOUNT ( Data[HeadlineID] )
VAR SummarizedTable =
    SUMMARIZE (
        ALLSELECTED ( Data ),
        Data[Media],
        "Unique_Item_Count", DISTINCTCOUNT ( Data[HeadlineID] )
    )
VAR ADDRANK =
    ADDCOLUMNS (
        SummarizedTable,
        "RANK",
            RANKX ( SummarizedTable, [Unique_Item_Count],, DESC, SKIP )
                + IF (
                    COUNTX (
                        FILTER (
                            SummarizedTable,
                            [Unique_Item_Count] = EARLIER ( [Unique_Item_Count] )
                        ),
                        [Unique_Item_Count]
                    ) > 1,
                    RANKX (
                        FILTER (
                            SummarizedTable,
                            [Unique_Item_Count] = EARLIER ( [Unique_Item_Count] )
                        ),
                        [Media],
                        ,
                        ASC,
                        DENSE
                    ) - 1
                )
    )
VAR CumulativeSum =
    SUMX (
        FILTER (
            ADDRANK,
            [RANK]
                <= SUMX ( FILTER ( ADDRANK, [Media] = MAX ( Data[Media] ) ), [RANK] )
        ),
        [Unique_Item_Count]
    )
RETURN
    CumulativeSum / Total_Unique_Item

Result is as below.

vrzhoumsft_0-1691046602236.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Yiyi ,

 

I suggest you to try code as below to create a measure.

Pareto =
VAR Total_Unique_Item =
    CALCULATE ( DISTINCTCOUNT ( Data[HeadlineID] ), ALLSELECTED ( Data ) )
VAR Current_Total_Unique_Item =
    DISTINCTCOUNT ( Data[HeadlineID] )
VAR SummarizedTable =
    SUMMARIZE (
        ALLSELECTED ( Data ),
        Data[Media],
        "Unique_Item_Count", DISTINCTCOUNT ( Data[HeadlineID] )
    )
VAR ADDRANK =
    ADDCOLUMNS (
        SummarizedTable,
        "RANK",
            RANKX ( SummarizedTable, [Unique_Item_Count],, DESC, SKIP )
                + IF (
                    COUNTX (
                        FILTER (
                            SummarizedTable,
                            [Unique_Item_Count] = EARLIER ( [Unique_Item_Count] )
                        ),
                        [Unique_Item_Count]
                    ) > 1,
                    RANKX (
                        FILTER (
                            SummarizedTable,
                            [Unique_Item_Count] = EARLIER ( [Unique_Item_Count] )
                        ),
                        [Media],
                        ,
                        ASC,
                        DENSE
                    ) - 1
                )
    )
VAR CumulativeSum =
    SUMX (
        FILTER (
            ADDRANK,
            [RANK]
                <= SUMX ( FILTER ( ADDRANK, [Media] = MAX ( Data[Media] ) ), [RANK] )
        ),
        [Unique_Item_Count]
    )
RETURN
    CumulativeSum / Total_Unique_Item

Result is as below.

vrzhoumsft_0-1691046602236.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello Rico, 

If you may still have some time, I would like to ask if it is possible to calculate the number of media accounting for 80% of all the items built on the code you provided. 

VAR Pareto = CumulativeSum / Total_Unique_Item 
VAR ROW_COUNT_80 = CALCULATE(COUNTROWS(SummarizedTable), FILTER( SummarizedTable, pareto < 0.8)) 
RETURN ROW_COUNT_80

I tried to add those below your code, but the number is a constant number (total amount of media). Can you kindly tell what is wrong here? 

Super cool! It works, thanks a lot!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.