Forum Discussion

Another_User's avatar
Another_User
Frequent Visitor
2 years ago
Solved

Calculation groups and Color measures

Hello, everybody.

 

I have a very simple bar visual with active and inactive computers. To color the bar, we use this measure called "ColorMeasure":

 

SWITCH (
    SELECTEDVALUE ( Device[Status] ),
    "Active", "#A80C00", "#3B791D"
)
 
To have an easy way to change between absolute numbers and %, I made a calculation group. One with the SELECTEDMEASURE() and the % formula, which is also really simple:
 
% (Percent) = DIVIDE(
    SELECTEDMEASURE(),
    [TotalDevices])
 
TotalDevices is a simple measure with a distinctcountnoblank of the Device[Name] of the field.
 
Well, the thing is that when we change to %, the numbers are ok, but the conditional formatting breaks. I sais that it can't conver the #A80C00" value to Number. It seems that the SELECTEDMEASURE is also trying to work over the Color measure, which is logic.
 
How could we solve this? I tried with 
% (Percent) = IF( CONTAINSSTRING(SELECTEDMEASURE(), "Color"), SELECTEDMEASURE(),
DIVIDE(SELECTEDMEASURE(), [TotalDevices]) )
 
but it doesn't work.
 
Thanks
 
 
 
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Another_User ,

    Thanks for amitchandak answer. Based on your reply, I have some ideas that I want to share.

     

     

     

    % (Percent) = IF( CONTAINSSTRING(SELECTEDMEASURE(), "Color"), SELECTEDMEASURE(),
    DIVIDE(SELECTEDMEASURE(), [TotalDevices]) )

     

     

     

    the approach won't work as expected because returns the value of the measure, not its name, and thus cannot be used to check the measure's

    To address this issue, you might consider the following approach:

    1. Separate Measures for Coloring: Ensure that measures used for conditional formatting (like your "ColorMeasure") are not included or referenced in calculation groups that perform numerical operations. This separation is crucial because calculation groups apply transformations to measure values, which is incompatible with the nature of color encoding measures.

    2. Use Calculation Items Conditionally: Instead of trying to exclude the "ColorMeasure" directly within the calculation item's formula, you can apply the calculation item conditionally in your report visuals. When setting up your visuals, explicitly use the appropriate measure (absolute numbers or percentage) and apply the "ColorMeasure" only for the visuals where it's relevant. This way, you avoid the calculation group's logic being applied to the "ColorMeasure".

    Best Regards,

    Xianda Tang

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

3 Replies

  • Another_User , if the selected measure is a color measure that returns a text it can not be used in dividing with Total devices.

    What exactly do you plan to achieve here

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Another_User ,

    Thanks for amitchandak answer. Based on your reply, I have some ideas that I want to share.

     

     

     

    % (Percent) = IF( CONTAINSSTRING(SELECTEDMEASURE(), "Color"), SELECTEDMEASURE(),
    DIVIDE(SELECTEDMEASURE(), [TotalDevices]) )

     

     

     

    the approach won't work as expected because returns the value of the measure, not its name, and thus cannot be used to check the measure's

    To address this issue, you might consider the following approach:

    1. Separate Measures for Coloring: Ensure that measures used for conditional formatting (like your "ColorMeasure") are not included or referenced in calculation groups that perform numerical operations. This separation is crucial because calculation groups apply transformations to measure values, which is incompatible with the nature of color encoding measures.

    2. Use Calculation Items Conditionally: Instead of trying to exclude the "ColorMeasure" directly within the calculation item's formula, you can apply the calculation item conditionally in your report visuals. When setting up your visuals, explicitly use the appropriate measure (absolute numbers or percentage) and apply the "ColorMeasure" only for the visuals where it's relevant. This way, you avoid the calculation group's logic being applied to the "ColorMeasure".

    Best Regards,

    Xianda Tang

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

    • technolog's avatar
      technolog
      Super User

      Anonymous hi! how did you do it finally?=) is it works for two level matrix eventually?