Reply
Another_User
Frequent Visitor
Partially syndicated - Outbound

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
 
 
 
1 ACCEPTED SOLUTION
avatar user
Anonymous
Not applicable

Syndicated - Outbound

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.

View solution in original post

3 REPLIES 3
avatar user
Anonymous
Not applicable

Syndicated - Outbound

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.

amitchandak
Super User
Super User

Syndicated - Outbound

@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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)