Forum Discussion

CupidC's avatar
CupidC
Icon for Helper II rankHelper II
4 years ago
Solved

Showing Top customers in a Table using TOPN

Hi all
I was trying to use TOPN function to show the Top 3 customers in a Table visual, but I couldn't figure it out what is wrong with my formula. any advice would be great 😞

 

Original Table:

A500
A300
A500
B700
B200
C323
C500
C300
D100
D700
D300
E220
E565
E667
F839
F122

 

My TopN Formula:

Top 3 customer =

VAR topcstuomer = topn(3,VALUES('Sales'[Name]),[Total sales],DESC)
Return
CALCULATE([Total sales],topcstuomer)
 
Result:
The result showing all customers instead of the top 3, but the total is correct - showing the sum of top3

 

 

Result that I hope for:

 

  • Hi CupidC 

     

    You can just add a simple filter on that visual like this to find those Top 3 items:

     

     

    Output:

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

     

  • Hi,

    Try these measures

    Total = SUM(Data[Sales])
    Measure = CALCULATE([Total],topn(3,ALL(Data[Customer]),[Total]),VALUES(Data[Customer]))

    Hope this helps.

4 Replies

  • Hi,

    Try these measures

    Total = SUM(Data[Sales])
    Measure = CALCULATE([Total],topn(3,ALL(Data[Customer]),[Total]),VALUES(Data[Customer]))

    Hope this helps.

    • CupidC's avatar
      CupidC
      Icon for Helper II rankHelper II

      HI Ashish

       

      Thanks. could you explain what "VALUES(Data[Customer])" does at the end..

       

      It works, but not sure why it works......

       

      Thanks

      Cupid

       

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

        The VALUES() function returns a unique list of all the Customers.  So while the TOPN function returns the top 3 from among all customers, the return result in the visual just has 3 customers. 

  • Hi CupidC 

     

    You can just add a simple filter on that visual like this to find those Top 3 items:

     

     

    Output:

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/