Forum Discussion

kjh252's avatar
kjh252
Frequent Visitor
6 years ago
Solved

Running Total based on Rank

Hi,   I have read many posts and have tried a number of different iterations and cannot seem to this to work. I am trying to get a running total of a column based on a rank.  I have the below code ...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Is this the result you want? (Refer to the RunningTotal field in the table below)

     

    Core FunctionComp_TotalvRankRunningTotal
    Procure to Pay Processing561.03115
    Capital Asset Coordination92.1459
    Policy & Regulatory Compliance63.0450
    PCard Coordinator63.0544
    Other63.0638
    Expense Report Processing & Approval63.0832
    Monitoring Travel Advance, Unused Airfare, and Prepaid Expenses54.0726
    Deposit Processing45.0921
    Accounts Receivable Processing45.1617
    Contract Review - Service Providers and IC's36.113
    T&M Uncleared Card Notifications27.0210
    Card Application Process27.138
    Accounts Receivable Aging27.176
    Training, Guidance & SME18.014
    Concur Reconciliation18.113
    Card Reporting18.122
    Annual Card Certification18.151

     

    In the table above named "TEMP", the first columns are from your sample data. The last two columns are calculated columns added using the following codes.

     

     

    vRank =
    VAR RankCT =
        RANKX ( Temp, Temp[Comp_Total], Temp[Comp_Total], DESC, DENSE )
    VAR RankCF =
        RANKX ( Temp, Temp[Core Function], Temp[Core Function], DESC, SKIP )
    VAR RankCTCF =
        RankCT + DIVIDE ( RankCF, 100, 0 )
    RETURN
        RankCTCF

     

    Disclaimer: In this vRank calculated column, I have given a ranking to your "Core Function" field to make the ranking unique. But that is by assuming that no two rows will have the same value in the "Core Function" field.

     

    RunningTotal =
    VAR CurrentRank = Temp[vRank]
    VAR RT =
        SUMX ( FILTER ( Temp, Temp[vRank] >= CurrentRank ), Temp[Comp_Total] )
    RETURN
        RT