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

IF Statement taking too long to execute

Hi,

 

I have created a multiple IF statement but the statement is taking too long to execute, is there a way around this?

My measure:

Trend = IF([Count Negative Results] = 6, "Losing",
IF([Count Negative Results] in {3,4,5} && [Average Moving and CY TTM] <= -.6 ,"Losing",
IF([Count Negative Results] in {4,5} && [Average Moving and CY TTM] <= -.15 && [Average Moving and CY TTM] > -.6, "Declining",
IF([Count Negative Results] in {4,5} && [Average Moving and CY TTM] < 0 && [Average Moving and CY TTM] > -.15, "Declining",
IF([Count Negative Results] = 3 && [Average Moving and CY TTM] <= -.15, "Downturn",
IF([Count Negative Results] in {1,2} && [Average Moving and CY TTM] < 0, "Potential Downturn",
IF([Count Negative Results] in {4,5} && [Average Moving and CY TTM] > 0, "Potential Recovery",
IF([Count Negative Results] in {1,2} && [Average Moving and CY TTM] > 0 && [Average Moving and CY TTM] < .15, "Growing",
IF([Count Negative Results] in {1,2,3} && [Average Moving and CY TTM] > .15 && [Average Moving and CY TTM] < .6, "Growing",
IF([Count Negative Results] in {1,2,3} && [Average Moving and CY TTM] > .6, "Winning",
IF([Count Negative Results] = 0, "Winning",
BLANK())))))))))))
2 ACCEPTED SOLUTIONS
mwarren
Frequent Visitor

Have you tried using 'SWITCH'?

 

Trend = SWITCH( TRUE() ,
[count negative results] = 6 , "Losing" ,
[count negative results] in {3,4,5} && [Average Moving and CY TTM] <= -.6 , "Losing" , 

etc....

 

This has sped up my nested IF statements in the past.

 

View solution in original post

Have you tried making a call the measures and storing as variables outside of the IF/SWITCH ?

 

Trend = 
var __CountNeg = [Count Negative Results]
var __AvgMov = [Average Moving and CY TTM]

RETURN

SWITCH(TRUE(),
__CountNeg = 6, "Losing", 
__CountNeg in {3,4,5} && __AvgMov <= -.6 ,"Losing", 
...

 

 

View solution in original post

8 REPLIES 8
mwarren
Frequent Visitor

Have you tried using 'SWITCH'?

 

Trend = SWITCH( TRUE() ,
[count negative results] = 6 , "Losing" ,
[count negative results] in {3,4,5} && [Average Moving and CY TTM] <= -.6 , "Losing" , 

etc....

 

This has sped up my nested IF statements in the past.

 

Anonymous
Not applicable

Thanks for the reply,
It worked faster than IF Statement, however, it still takes around 5 minutes to execute, is there any other workaround?

Thanks again!

Next thing i would think of is looking at the measures you are referencing in statement and see if there is a way you could run those more efficiently.  

 

Also maybe VAR them in the function instead of referencing them? I definately think 5 minutes is too long to run that statement though.

Anonymous
Not applicable

Hey,

 

Thanks for the above inputs, I have different measures and i am counting the frequency of negative values of those measure. I dont find any other way to add these measures, please help!

 

Count Negative Results = IF([TTM Var 1] < 0,1,0) + IF([TTM Var 2] < 0,1,0) + IF([TTM Var 3] < 0,1,0) + IF([TTM Var 4] < 0,1,0) + IF([TTM Var 5] < 0,1,0) + IF([TTM Var 6] < 0,1,0)
 
Using If statement is the problem here for large computational time, please guide me if there is a way around.
 
Thanks!

Have you tried making a call the measures and storing as variables outside of the IF/SWITCH ?

 

Trend = 
var __CountNeg = [Count Negative Results]
var __AvgMov = [Average Moving and CY TTM]

RETURN

SWITCH(TRUE(),
__CountNeg = 6, "Losing", 
__CountNeg in {3,4,5} && __AvgMov <= -.6 ,"Losing", 
...

 

 

Anonymous
Not applicable

Worked like a charm! Thank you all!

Hey @Anonymous,

 

please mark the most helpful post as an answer, as it also helps others in this forum.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Instead of a measure try doing that for a calculated column. This way it will do the calculation when it brings in the data rather than at the time you are trying to run the query. 

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.