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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

SWITCH terrible performance issue

Hello everyone,

I am making a dynamic formula that depending on user selection should choose the underlying measure to kick-in.
I have used this technique a couple of times and never had issue, but now its incredible slow.

My code is the following:

test = 
var hasfilter = HASONEFILTER('Sales Reset'[ResetValue]) var salesMeanrolling = [SalesRolling Mean] var valueselected = VALUES('Sales Reset'[ResetValue])
return
IF(hasfilter, SWITCH(TRUE(),valueselected =0,[SalesNoReset Mean], valueselected =1,salesMeanrolling, valueselected =2,[SalesReset2M Mean], valueselected =3,[SalesReset3M Mean], valueselected =4,[SalesReset4M Mean], valueselected =6,[SalesReset6M Mean], valueselected =12,[SalesReset12M Mean]),salesMeanrolling)

The performance of using the direct formula vs using the direct formula is insanely different and I cant comprehend why..
I am assuming the valueselected condition gets evaluated fast thus jumping quite fast to the underlying measure, but somehow this is not happening.

Any ideas on why such behavior can happen?

Thanks!
4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

I think it is caused by the large data and complex calculation. I modified your formula. It might calculate a little faster.

 

test = 
var valueselected = SELECTEDVALUE('Sales Reset'[ResetValue])
return
SWITCH( HASONEFILTER('Sales Reset'[ResetValue]), valueselected =0,[SalesNoReset Mean], valueselected =1,salesMeanrolling, valueselected =2,[SalesReset2M Mean], valueselected =3,[SalesReset3M Mean], valueselected =4,[SalesReset4M Mean], valueselected =6,[SalesReset6M Mean], valueselected =12,[SalesReset12M Mean], [SalesRolling Mean])

Best Regards,

Xue Ding

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

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks for the reply. In my case I cannot use the SELECTEDVALUE as its an older Tabular version but will use the equivalent and give it a go with your approach and reply here then

Anonymous
Not applicable

Unfortunately there are no improvements

Anonymous
Not applicable

Hi @Anonymous 

I noticed same behaviour in my dataset, and i found some insipiration on this link: https://www.sqlbi.com/articles/optimizing-mutually-exclusive-calculations/

 

IS it possible to rewrite your measures so that you user switch to calcualte filter and then call only one or lower number calcualte statements

 

 

test = 
var valueselected = SELECTEDVALUE('Sales Reset'[ResetValue])
var vFilter=
SWITCH( HASONEFILTER('Sales Reset'[ResetValue]), valueselected =0,"SalesNoReset Mean", valueselected =1,"salesMeanrolling", valueselected =2,"SalesReset2M Mean", valueselected =3,"SalesReset3M Mean", valueselected =4,"SalesReset4M Mean", valueselected =6,"SalesReset6M Mean", valueselected =12,"SalesReset12M Mean"
, "SalesRolling Mean")

RETURN CALCULATE([SalsesMeasure],FilterColumn = vFilter)

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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