Forum Discussion

alexei7's avatar
alexei7
Continued Contributor
7 years ago
Solved

RANKX DAX column help

Hi,

I'm trying to create a column that will rank Invoices across Suppliers.

This needs to be a column so that I can then use this Rank column to create a cumulative total and then (hopefully a measure to flag/show the Suppliers which make up the top 80% of our spend.

Having googled and browsed this forum i'm struggling to come up with something that works for me.

 

My data looks like this:

 

SupplierCodeInvoiceNumberInvoice Amount
S1000000:892347892£100
S1000001Jeff:2343234£101
S1000002Jeff:239048912£10
S1000002Susan:93240923£5
S1000002:9239239£50
S1000003:2930499023£25
S1000001Greg:8293489£5

 

I want to create either of the two results:

 

1. A table with the extra rank column, where rank is appled based on the total across the SupplierCode

SupplierCodeInvoiceNumberInvoice AmountRank
S1000000:892347892£1002
S1000001Jeff:2343234£1011
S1000002Jeff:239048912£103
S1000002Susan:93240923£53
S1000002:9239239£503
S1000003:2930499023£254
S1000001Greg:8293489£51

 

2. If the above is not possible, a derived table such as the below:

SupplierCodeInvoice AmountRank
S1000000£1002
S1000001£1011
S1000002£103
S1000003£54

 

Much appreciated,

Alex

  • alexei7

     

    As a calc column,,,try

     

    Calc Column =
    RANKX (
        Table1,
        CALCULATE (
            SUM ( [Invoice Amount] ),
            ALLEXCEPT ( Table1, Table1[SupplierCode] )
        ),
        ,
        DESC,
        DENSE
    )
    

5 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    alexei7

     

    As a calc column,,,try

     

    Calc Column =
    RANKX (
        Table1,
        CALCULATE (
            SUM ( [Invoice Amount] ),
            ALLEXCEPT ( Table1, Table1[SupplierCode] )
        ),
        ,
        DESC,
        DENSE
    )
    
    • alexei7's avatar
      alexei7
      Continued Contributor

      Thanks for your help Zubair_Muhammad

       

      Unfortunately this isn't working for me.

       

      I probably should have mentioned that my dataset includes about 30 other columns (which are not required for this calculation). I guess that might be important when using ALLEXCEPT.

       

       

      See below for dummy data with the formula you helped with:

       

      Supplier Code

      Invoice Amount

      * Rank Column

      S687255

       £             23,029,923

      4

      S241863

       £               1,100,000

      52

      S712616

       £               2,700,210

      75

      S331533

       £               3,700,210

      126

      S943796

       £                   800,000

      126

      S14822

       £                   200,000

      132

      S229347

       £                   400,000

      163

      S714313

       £               6,333,333

      168

      S18322

       £                   100,000

      214

      S69059

       £                     52,000

      215

      S628244

       £                   120,000

      230

       

      Any further ideas?

      Thanks again

      Alex

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        alexei7

         

        Any number of columns shouldn't make a difference I believe.

         

        Could you share your file?

         

        Is the result below from a Table Visual in Report....Perhaps it is summing the RANKs...may be you need to mark the RANK column as "Dont summarize"

        Could you share screen shot from dataview

         

  • v-frfei-msft's avatar
    v-frfei-msft
    Community Support

    Hi alexei7,

     

    To create two measures as below.

     

    total = CALCULATE(SUM(Table1[Invoice Amount]),ALLEXCEPT(Table1,Table1[SupplierCode]))
    rankx = RANKX(ALLSELECTED(Table1[SupplierCode]),[total],,DESC,Skip)

     

    Also to create a calculated columm worked well.

     

    rankxcc = RANKX(ALLSELECTED(Table1[SupplierCode]),[total],,DESC,Skip)

     

    For more details, please check the pbix as attached.

     

    Regards,

    Frank