Forum Discussion
IF Statement taking too long to execute
- 7 years ago
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.
- 7 years ago
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", ...
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.
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!
- mwarren7 years agoFrequent Visitor
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.
- Anonymous7 years agoNot 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!- dedelman_clng7 years agoCommunity Champion
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", ...