Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Another_User
Frequent Visitor

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
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.

View solution in original post

3 REPLIES 3
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.

amitchandak
Super User
Super User

@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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.