Forum Discussion

dgiacchino's avatar
dgiacchino
Frequent Visitor
3 years ago
Solved

Dax measures to create conditional formatting

Hi, maybe someone can help me. The measure that can be seen below, aims to give a color format to the different cells of a variable in a Matrix. The reality is that it works, but I have a problem...
  • rubayatyasmin's avatar
    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? 

     

     

  • dgiacchino's avatar
    dgiacchino
    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.