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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
giuliapiazza94
Helper IV
Helper IV

Change color based on TOTAL

Hi guys,

i need to change color of measure based on the total.

For Example:

 

 CustomersTotal Sales Sales Item X% item X Sales Item Y% item Y
 A100 2020% 8080%
 B500 30060% 20040%
 C120 108% 11092%
 D60 4067% 2033%
 E430 40093% 307%
         
Total 1210 77064% 44036%

 

item X = the values 20%, 60%, 8% are red because are less then 64%

               the values 67% and 93% are green because are grater then 64%

 

 

item Y = the value 7% is red because is less then 36%

              the values 80%, 40%, 92% and 33% are green because are grater then 36%

 

How can I set the color?

Thank you all 😁

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @giuliapiazza94 ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:

1. Create two measures as below

 

XConditional formatting = 
VAR _x =
    CALCULATE ( SUM ( 'Table'[Sales Item X] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _y =
    CALCULATE ( SUM ( 'Table'[Sales Item Y] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _total = _x + _y
VAR _xper =
    DIVIDE ( _x, _total )
RETURN
    IF ( [% item X] < _xper, "red", "green" )
YConditional formatting = 
VAR _x =
    CALCULATE ( SUM ( 'Table'[Sales Item X] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _y =
    CALCULATE ( SUM ( 'Table'[Sales Item Y] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _total = _x + _y
VAR _yper =
    DIVIDE ( _y, _total )
RETURN
    IF ( [% item Y] < _yper, "red", "green" )

 

2. Configure conditional formatting

yingyinr_0-1674108715293.png

If the above one can't help you get the expected result, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @giuliapiazza94 ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:

1. Create two measures as below

 

XConditional formatting = 
VAR _x =
    CALCULATE ( SUM ( 'Table'[Sales Item X] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _y =
    CALCULATE ( SUM ( 'Table'[Sales Item Y] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _total = _x + _y
VAR _xper =
    DIVIDE ( _x, _total )
RETURN
    IF ( [% item X] < _xper, "red", "green" )
YConditional formatting = 
VAR _x =
    CALCULATE ( SUM ( 'Table'[Sales Item X] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _y =
    CALCULATE ( SUM ( 'Table'[Sales Item Y] ), ALLSELECTED ( 'Table'[Customers] ) )
VAR _total = _x + _y
VAR _yper =
    DIVIDE ( _y, _total )
RETURN
    IF ( [% item Y] < _yper, "red", "green" )

 

2. Configure conditional formatting

yingyinr_0-1674108715293.png

If the above one can't help you get the expected result, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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