Forum Discussion

Yiyi's avatar
Yiyi
Icon for Helper I rankHelper I
3 years ago
Solved

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 ...
  • Anonymous's avatar
    Anonymous
    3 years ago

    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.

     

    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.