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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KarolDmo
Regular Visitor

Rankx with switch and field parameters - performance issue

Hello ! 

I would like to have dynamic top 5 KDU on visuals - taking into consideration current filtering and also Measure selection (using field parameters and switch function). 

It result with bad performance and usually error with not sufficent memory. The Dax which I have tried looks like this:

 

KDU RANK =
var KDU = ALLSELECTED(Data[KDU])

RETURN
SWITCH(TRUE(),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 0,RANKX(KDU,[Total vs PC]) ,
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 1,RANKX(KDU,[Std Cost vs PC]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 2,RANKX(KDU,[Std vs PC]) ,
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 3,RANKX(KDU,[Std Costs 3rd vs PC]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 4,RANKX(KDU,[company Purchases vs PC]) ,
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 5,RANKX(KDU,[Other vs PC]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 6,RANKX(KDU,[Total Volume vs PC]) ,
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 7,RANKX(KDU,[Total net]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 8,RANKX(KDU,[Std Cost net]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 9,RANKX(KDU,[Std net]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 10,RANKX(KDU,[Std Costs 3rd net]) ,
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 11,RANKX(KDU,[company Purchases net]),
SELECTEDVALUE('Measure Selection'[Measure Selection Order])= 12,RANKX(KDU,[Other net])
)

 

Any ideas how to use rankx with good performance with dynamic measure selection ?

 

1 REPLY 1
amitchandak
Super User
Super User

@KarolDmo , Try like

 

KDU RANK =
var KDU = ALLSELECTED(Data[KDU])
var _sel = SELECTEDVALUE('Measure Selection'[Measure Selection Order])
var _mes = SWITCH(_sel
,
0, [Total vs PC],
1, [Std Cost vs PC],
2, [Std vs PC],
3, [Std Costs 3rd vs PC],
4, [Company Purchases vs PC],
5, [Other vs PC],
6, [Total Volume vs PC],
7, [Total net],
8, [Std Cost net],
9, [Std net],
10, [Std Costs 3rd net],
11, [Company Purchases net],
12, [Other net]
)


RETURN
RANKX(KDU,_mes)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.