Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
s15
Helper III
Helper III

DAX or Measure to show top largest values

Hi all,

 

I have a list of products and sales revenues. I want to list only 10 products which have the highest sales value. What kind of function can I use in this case?

 

Saying the product column is "Product" and the sales revenue is "Sales".

 

Thank you.

1 ACCEPTED SOLUTION
vanessafvg
Community Champion
Community Champion

@s15

 

when you say its wrong ,  is it because the total is wrong?  are you filtering on anything else?    or is because its not the top, you should change your asc to desc if you want the top

 

in terms of the measure you should be able to, for readbility though i would probably change the measure to this

 

 

Top 2 =
VAR totalSales =
    SUM ( financials[ Sales] )
RETURN
    CALCULATE (
        totalSales,
        FILTER (
            VALUES ( financials[Product] ),
            IF (
                RANKX ( ALL ( financials[Product] ), [Total Sales],, desc) <= 2,
                [Total Sales],
                BLANK ()
            )
        )
    )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

10 REPLIES 10
vanessafvg
Community Champion
Community Champion

@s15 first you need to rank your data by you sales

 

then you should return only where top 10

 

this video is helpful ti figure it out

 

https://www.youtube.com/watch?v=hX-s1htBdmk





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




I know I can rank by using filter but I'd like to learn more from DAX.

 

ranking.PNG

Thank you @vanessafvg

I followed the measure in the video but the ranking is not correct.

 

sales.PNG

Firstly I created a measure to reflect to the Sales column.

 

 

Total Sales = sum(financials[ Sales])

 

 

Secondly I created the measure below

 

Top 2 = 
CALCULATE([Total Sales],
	FILTER(VALUES(financials[Product]),
		IF(RANKX(ALL(financials[Product]),[Total Sales],,ASC)<=2,[Total Sales],BLANK())))

Another question is: Do I have to create the first measure?  Can I replace [Total Sales] by SUM((financials[ Sales]) in the second measure directly?

 

Thank you

 

 

vanessafvg
Community Champion
Community Champion

@s15

 

when you say its wrong ,  is it because the total is wrong?  are you filtering on anything else?    or is because its not the top, you should change your asc to desc if you want the top

 

in terms of the measure you should be able to, for readbility though i would probably change the measure to this

 

 

Top 2 =
VAR totalSales =
    SUM ( financials[ Sales] )
RETURN
    CALCULATE (
        totalSales,
        FILTER (
            VALUES ( financials[Product] ),
            IF (
                RANKX ( ALL ( financials[Product] ), [Total Sales],, desc) <= 2,
                [Total Sales],
                BLANK ()
            )
        )
    )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thanks for this expression! Helped out a lot!

I am sorry, but this solution is wrong. When I trie this, it shows the complete total, not the topn

 

this does neot work:

 

Top 2 =
VAR TotalSalesVar =
SUM ( tblfinancials[Sales] )
RETURN
CALCULATE (
TotalSalesVar;
FILTER (
VALUES ( tblfinancials[Product] );
IF (
RANKX ( ALL ( tblfinancials[Product] ); TotalSalesVar;; desc) <= 2;
TotalSalesVar;
BLANK ()
)
)
)

@vanessafvg Thank you for your suggestion. Changing to desc works well.

 

For the second question, can I just have only one measure in which I can have to sub-measures?

 

From your measure, it seems not to work in my environment even when you set totalSales as a variable. totalSales seems not to passed to expression inside RANKX

 

total.PNG

 

vanessafvg
Community Champion
Community Champion

@s15 remove the [ brackets i think you using a variable





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thank you @vanessafvg

 

I make it a variable but now it seems not to be working. I think DESC with 2 is OK but somehow it doesn't filter two products.

 

somehow.PNG

vanessafvg
Community Champion
Community Champion

@s15 can you bring the ranking back as well?  ive picked up one issue and that is the

 

  CALCULATE(SUM ( Sales[TotalCost] ))

 

need to have a calculate in front of it as all the ranking one will be 1.

 

i think the calculation is incorrect, need to check it out properly on video, will look at later





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.