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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Ho to compare two rows, and color the cell which satisfies the conditional formatting

I have the following data:

apeksha_0-1658949949056.png

 

I want to colour XA green, if XA>YA and red, if not.

Similarly colour XB green if XB>YB and red if not.

 

Is this possible in PBI, will i need to create a measure?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Well, you can create measures like

Measure = 
var _XA=CALCULATE(SUM('Table'[A]),FILTER(ALL('Table'),[Region]="X"))
var _YA=CALCULATE(SUM('Table'[A]),FILTER(ALL('Table'),[Region]="Y"))
RETURN IF(_XA>_YA&&MAX('Table'[Region])="X","green",IF(_XA<=_YA&&MAX('Table'[Region])="X","red"))
Measure 2 = 
var _XB=CALCULATE(SUM('Table'[B]),FILTER(ALL('Table'),[Region]="X"))
var _YB=CALCULATE(SUM('Table'[B]),FILTER(ALL('Table'),[Region]="Y"))
RETURN IF(_XB>_YB&&MAX('Table'[Region])="X","green",IF(_XB<=_YB&&MAX('Table'[Region])="X","red"))

Set up the conditional formatting as follows.

vstephenmsft_0-1659346726325.png

vstephenmsft_1-1659346733789.png

Apply conditional table formatting in Power BI - Power BI | Microsoft Docs

 

 

 

Best Regards,

Stephen Tao

 

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 @Anonymous ,

 

Well, you can create measures like

Measure = 
var _XA=CALCULATE(SUM('Table'[A]),FILTER(ALL('Table'),[Region]="X"))
var _YA=CALCULATE(SUM('Table'[A]),FILTER(ALL('Table'),[Region]="Y"))
RETURN IF(_XA>_YA&&MAX('Table'[Region])="X","green",IF(_XA<=_YA&&MAX('Table'[Region])="X","red"))
Measure 2 = 
var _XB=CALCULATE(SUM('Table'[B]),FILTER(ALL('Table'),[Region]="X"))
var _YB=CALCULATE(SUM('Table'[B]),FILTER(ALL('Table'),[Region]="Y"))
RETURN IF(_XB>_YB&&MAX('Table'[Region])="X","green",IF(_XB<=_YB&&MAX('Table'[Region])="X","red"))

Set up the conditional formatting as follows.

vstephenmsft_0-1659346726325.png

vstephenmsft_1-1659346733789.png

Apply conditional table formatting in Power BI - Power BI | Microsoft Docs

 

 

 

Best Regards,

Stephen Tao

 

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

Anonymous
Not applicable

this was extremely helpful, thank you! it works fine.

I also wanted to check incase we have more countries how can this be done? the ouput should be similar

I want to colour XA green, if XA>YA and red, if not.

Similarly colour XB green if XB>YB and red if not.

 

Attaching a table for such a situation:

Region     A   B  Country
X    42.00%    0.60%    France  
Y    42.20%  2.20%    France
X  42.00%  10.80%  UK
Y  43.00%  23.00%  UK
lbendlin
Super User
Super User

Yes, you need measures, and you need an index column so Power Query and Power BI can understand what you mean when you say "compare rows". 

 

Please provide sanitized sample data that fully covers your issue. I cannot help you without usable sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. I cannot use screenshots of your source data.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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