DAX TOPN function

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hi,

I've been trying to use topn to get the Nth hightest, selling item, I've tried ;


Excel Formula:
EVALUATE
TOPN(4,VALUES( Table1[Item]) ,[totalUnits] )


and then thought to wrap this in a MINX to get the 4th top Item,,

Excel Formula:
MINX( TOPN(4,VALUES( Table1[Item]) ,[totalU] ), Table1[Item] )


This does not work, it gives the Min of the items, based on alphabet, So essentially I was trying to get a virtual table of the top 4 values based on Units, and then return the min ie 4th, Item from the ranked Units .

Richard.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Why specify Item rather than totalU as the MINX expression then?
 
Upvote 0
I may want to use RANX?
If I use ;

Excel Formula:
TOPN(4, 
Table1,[Tunits] ,DESC)

I get a four row two column table Item, Units , I was then trying to return the Item associated with the lowest value unit in the returned table. So below ; q.

1679403952398.png


Richard.
 
Upvote 0
What if there is more than one item with the 4th largest units?
 
Upvote 0
What if there is more than one item with the 4th largest units?
No idea, it seems to treat ties the same way they do in golf, I've tried using a rank measure ;

MINX(TOPN( 3, Table1,[Rankm] ), Table1[Item]), but falis for same reason as above.

EVALUATE
TOPN( 3, Table1, [Rankm] ,DESC ) , the Rank measure sorted ASC,
 
Upvote 0
I mean what do you want to happen if there is more than one?
 
Upvote 0
I mean what do you want to happen if there is more than one?
I'm not sure, I'm going to have to think about this some more. I find the TOPN function a bit confusing, with the ASC , DESC , which when used with isnonorafter makes sense, and also the 'order by option.

Richard.
 
Upvote 0

Forum statistics

Threads
1,223,362
Messages
6,171,640
Members
452,413
Latest member
N3edHelp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top