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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
smpa01
Super User
Super User

Use of TOPN in a measure

Hi,

My source data is following

NameValue
P1100
P2200
P3300
P4400
P5500
P6600

From here, I want to come here

NameValue
P3300
P1100
P2200

which can be achieved by creating a

newTable = TOPN(3,'Fact','Fact'[Name],ASC)

 

Now, I want to acheive the following by using it inside a measure and I could not make it to work.

Capture.PNG

 

Can someone please point me to the correct direction.

Thank you in advance.

 

topn = SUMX(TOPN(3,'Fact','Fact'[Name],ASC),'Fact'[Value])

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
4 REPLIES 4
Anonymous
Not applicable

Hi @smpa01 ,

 

Try this measure

rank =
SUMX (
    FILTER (
        'Fact',
        RANKX ( ALL ( 'Fact' ), CALCULATE ( MAX ( 'Fact'[Name] ) ),, ASC, DENSE ) <= 3
    ),
    [Value]
)

Screenshot 2021-03-22 172326.png

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous  thanks for looking into this. I know how to get to the desired result using RANKX. I was trying to see if I can get there using TOPN.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@smpa01 , Try if this measure can help

 

topn = SUMX(filter('Fact', 'Fact'[Name] in TOPN(3,'Fact','Fact'[Name],ASC)),'Fact'[Value])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandakthanks for looking into this. It did not workCapture.PNG

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

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.