Forum Discussion

Redraidas1's avatar
Redraidas1
Helper I
5 years ago
Solved

How to get TOP10

I'm trying to limit my DAX top give me the the SUM of TOP10 sales, however, DAX seems to be ignoring my TOP10 request and won't limit the caluclation to TOP 10 only. Any ideas? Thanks!
 
CALCULATE (
SUM ( AfterSales_BM[ABCValue] ),
TOPN( 10, AfterSales_BM, AfterSales_BM[ABCValue]),
FILTER (
Config,
Config[FieldCode] = "1"
  )
)
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Redraidas1 ,

     

    You could consider to create a measure using RANKX() function.

    Then add this measure to filter to filter the data that rank value is less than 10.

    For example:

    _sum = SUM('Table'[value])
    
    _rank = RANKX(ALL('Table'),[_sum])

     

     

    Best Regards,

    Jay

5 Replies

  • VijayP's avatar
    VijayP
    Community Champion

    Redraidas1 

    CALCULATE (
    SUM ( AfterSales_BM[ABCValue] ),
    TOPN( 10, AfterSales_BM, AfterSales_BM[ABCValue]),
    FILTER (
    Config,
    Config[FieldCode] = "1"
      ),Distinct(ColumnName)
    )
    The bold one is which column you want to see the Rank (most probably AferSales_BM)?!
    Please do let me know whether this helped!
     
    • Redraidas1's avatar
      Redraidas1
      Helper I

      I changed it, but the problem is still there.

      DAX:

      CALCULATE (
       
      SUM ( AfterSales_BM[ABCValue] ),
      TOPN( 5, AfterSales_BM, AfterSales_BM[ABCValue]),
      FILTER (
      Dim_Report_Config,
      Dim_Report_Config[FieldCode] = "1"
      ), DISTINCT(AfterSales_BM[ABCValue])
      )
  • VijayP's avatar
    VijayP
    Community Champion

    Redraidas1 

    Use this Function
    VAR = RankofABC = Rankx(all(AfterSales_BM[ColumnName]),sum(abcvalue))
    return
    calculate(sum(abcvalue),filter(all(all(AfterSales_BM[ColumnName]),RankofABC<=10),distinct(columname))

  • Redraidas1 it is not as straightforward as it looks like, you are doing top 10 on a table and also filtering on another table. Also what are your expectation when you are seeing the data below, let's say we want the top 3 (would you like to see (200 + 40 + 30, = 270 since these are top 3 values ), or you want it to sum by the customer and then take top 3 in that case from the data below the result will be (A = 15, B = 30, C = 200, D = 70 and top 3 will be then 200 + 70 + 30 = 300)

     

    A - 10

    A - 5

    B - 20

    B - 10

    C - 200

    D - 30

    D - 40

     

    It will be easier if you share pbix file using one drive/google drive with the expected output. Remove any sensitive information before sharing.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Redraidas1 ,

     

    You could consider to create a measure using RANKX() function.

    Then add this measure to filter to filter the data that rank value is less than 10.

    For example:

    _sum = SUM('Table'[value])
    
    _rank = RANKX(ALL('Table'),[_sum])

     

     

    Best Regards,

    Jay