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
SKPowerBINewbie
New Member

PowerBI Table - How to colour code cells based on values in the row

Hi , 

I have a Power BI report that dispalys data in a table that displays data like this 

CriteriaM1M2M3M4M5M6M7M8M9M10
Cr11553245112333461
Cr25545442133255522
Cr30775664422159953
Cr455286055576741255
Cr522334455322232635954

 

What I want is to colour columns M1 to M10 with colour 'Red' , based on what cell value being > than specific values are indicated below.

So , if Criteria = Cr1 and if any of M1 to M10 is > 10 that cell be colured RED , else colour them Green.

Similarly , if if Criteria = Cr2 and if any of M1 to M10 is > 21 that cell be colured RED , else colour them Green.

 

CriteriaColour Cell Red when Criteria > than 
Cr110
Cr221
Cr35
Cr422
Cr540

 

The Final table should look like this 

SKPowerBINewbie_0-1657015634955.png

How do I achieve this in PowerBI. Any guidance will be much appreciated.

1 ACCEPTED SOLUTION

Hi @SKPowerBINewbie ,

 

If you want to use conditonal formatting in table visual, there should be multiple columns M1/M2...M10 in table value field, you need to create color measures for each columns.

Here I create a sample to have a test.

RicoZhou_0-1657616935784.png

You should need to create 10 color measures in total for each M column. Here I create a color measure for M1 as a sample.

 

Color for M1 = 
IF(SUM('Table (table visual)'[M1])> SUM('Table 2'[Colour Cell Red when Criteria > than ]),"Red","Green")

 

We can drop down and select the columns we need to use conditional formatting in Format.

RicoZhou_1-1657617027168.png

Here we select M1 and use [Color for M1] in Field value in Background color.

RicoZhou_2-1657617122967.png

You can repeat the above operation to add conditional formatting for other M columns.

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
v-rzhou-msft
Community Support
Community Support

Hi @SKPowerBINewbie ,

 

The calculation in Power BI is based on columns. Your data model have multiple columns like M1/M2... and so on. This will complicate your calculations. So I suggest you to transform your data model with Unpivot function in Power Query Editor and then create a measure and use this measure in matrix conditional formatting.

Table1 will look like as below after unpivoting.

RicoZhou_0-1657272998637.png

Relationship:

RicoZhou_1-1657273014268.png

Color measure:

Color =
VAR _Compare_Value =
    CALCULATE (
        SUM ( 'Table 2'[Colour Cell Red when Criteria > than ] ),
        FILTER ( 'Table 2', 'Table 2'[Criteria] = MAX ( 'Table 1'[Criteria] ) )
    )
RETURN
    IF ( SUM ( 'Table 1'[Value] ) > _Compare_Value, "Red", "Green" )

Conditional formatting and result is as below.

RicoZhou_2-1657273090617.png

 

Best Regards,
Rico Zhou

 

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

 

 

Hi Rico Zhou , 

Thank you very much for taking the time to help me out . 

Your proposed solution works but I have to use output the report into a matrix visual.

It will not fit in with my current design of a table matrix 

Hi @SKPowerBINewbie ,

 

If you want to use conditonal formatting in table visual, there should be multiple columns M1/M2...M10 in table value field, you need to create color measures for each columns.

Here I create a sample to have a test.

RicoZhou_0-1657616935784.png

You should need to create 10 color measures in total for each M column. Here I create a color measure for M1 as a sample.

 

Color for M1 = 
IF(SUM('Table (table visual)'[M1])> SUM('Table 2'[Colour Cell Red when Criteria > than ]),"Red","Green")

 

We can drop down and select the columns we need to use conditional formatting in Format.

RicoZhou_1-1657617027168.png

Here we select M1 and use [Color for M1] in Field value in Background color.

RicoZhou_2-1657617122967.png

You can repeat the above operation to add conditional formatting for other M columns.

 

Best Regards,
Rico Zhou

 

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

 

Hi Rico Zhou , 

Yes, that worked . I ended up created a measure for each column and using conditional formatting . Thank you very much for your help and guidance.

Smalfly
Resolver III
Resolver III

Hi @SKPowerBINewbie ,

 

try to follow these steps:

  • select the table you want to edit
  • go to 'format visual' > cell elements > turn background color on

Smalfly_0-1657204265236.png

 

  • This will open a pop-up you can use to set the color rules.

Smalfly_1-1657204436203.png

 

  • Repeat this for columns M2 -- M10...

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.