Forum Discussion

scootzinc's avatar
scootzinc
Frequent Visitor
3 years ago
Solved

Need help with dynamic ranking using dax

vendor group year invoice # spend 1002 A 2023 10001  $  3,275,404.00 1002 A 2023 10002  $  3,919,979.00 1002 B 2022 10003  $  3,320,...
  • Jihwan_Kim's avatar
    3 years ago

    Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    Spend: =
    SUM ( Data[spend] )
    

     

    Rank: =
    RANKX ( ALL ( vendor[vendor] ), [Spend:],, DESC )
    

     

    spend cumulate classify =
    VAR _allspend =
        CALCULATE ( [Spend:], ALL ( vendor[vendor] ) )
    VAR _cumulatespend =
        CALCULATE (
            [Spend:],
            WINDOW (
                1,
                ABS,
                0,
                REL,
                ADDCOLUMNS ( ALL ( vendor[vendor] ), "@spend", [Spend:] ),
                ORDERBY ( [@spend], DESC )
            )
        )
    VAR _percentage =
        DIVIDE ( _cumulatespend, _allspend )
    RETURN
        IF (
            HASONEVALUE ( vendor[vendor] ),
            IF ( _percentage <= 0.8, "top80%", "bottom20%" )
        )