Forum Discussion
Dax measures to create conditional formatting
- 3 years ago
Hi, dgiacchino
I can see that [Dist/Min] has been called in this code repetitively. How about saving this measure in a variable? And then use it. This should optimize the memory. And how about calculating the difference between [Dist/min] and [_AvgSession] then storing it in another variable then using it for further calculation? Also, Use SWITCH instead of nested IFs.
something like this:
VAR _DistPerMin = [Dist/min] VAR _DistDiff = _DistPerMin - _AvgSession VAR _ColourClassIntraSession = SWITCH ( TRUE(), _DistDiff >= 2 * _DstPSession, "#75C050", _DistDiff >= 1 * _DstPSession, "LightGreen", _DistDiff >= 0.5 * _DstPSession, "#FFDB41", _DistDiff >= -0.5 * _DstPSession, "LightYellow", _DistDiff >= -1 * _DstPSession, "#ECC596", _DistDiff >= -2 * _DstPSession, "#F29C21", _DistPerMin > 0, "#EFB5B9", BLANK () )do the same for _indRefGame. Calculate the difference then use it for calculation. Also in the return statement, you can remove 3 and only use the variable. It should by default return that variable. Right?
- 3 years ago
Use the two measures on 3 variables, only modifying the return option.
It is important to clarify that the data that was compared was the time it takes to load the matrix, after selecting option 1, 2 or 3.
What I could observe, after doing it several times and only having three active variables.
Using the average used by the VAR _RESULTADO, the loading times were 2037, 1638, 1732.
In the other case, the times were 2060, 1874, 1789.
Something important, that I was able to observe, is that even though it improves, the process continues to be slow.
I'm working with parameters, where I included many variables and these format measures affect performance a lot.
Another aspect that may be useful to someone who sees this is that having a dashboard, with many filters, cards, etc. It is essential to use the tool to apply the filters all together, otherwise all the modifications that affect each section are loaded many times.
If you have any other comments, they will be welcome.
Ft_Colour_Dist/min PRUEBA =
Do we need to store the result in a variable? we are not using that statement any further to this code right? How about just using return statement? Like this
RETURN SWITCH( _ValorFiltro, 1, _ColourClassIntraSession, 2, _ColorClassSessVsIRG, _ColourClassIntraSession)
see if it improves the performance or not. Would have been better if you could find a way to make it within one switch statement. Just an Idea.
Thanks
Did I help? If yes, hit 👍, accept this solution as the answer.
- dgiacchino3 years agoFrequent Visitor
In this optimized code, I have calculated the result of the SWITCH in the _Result variable and then used _Result to return the final result. This avoids duplicating the calculation of _ColourClassIntraSession and improves the overall performance of the measure.
I'm not sure this is entirely correct.
I will compare the two options.
- rubayatyasmin3 years ago
Community Champion
Let me know, I am curious as well
- dgiacchino3 years agoFrequent Visitor
Use the two measures on 3 variables, only modifying the return option.
It is important to clarify that the data that was compared was the time it takes to load the matrix, after selecting option 1, 2 or 3.
What I could observe, after doing it several times and only having three active variables.
Using the average used by the VAR _RESULTADO, the loading times were 2037, 1638, 1732.
In the other case, the times were 2060, 1874, 1789.
Something important, that I was able to observe, is that even though it improves, the process continues to be slow.
I'm working with parameters, where I included many variables and these format measures affect performance a lot.
Another aspect that may be useful to someone who sees this is that having a dashboard, with many filters, cards, etc. It is essential to use the tool to apply the filters all together, otherwise all the modifications that affect each section are loaded many times.