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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Calculated Field to Conditional Formatting

Hey All,

 

So I am trying to build a calculated field to show this :

12.PNG

For some of the rows I need if the actual is higher then budget the it will show green but also for some of them if actual is higher the  show red. any help would be greatly apprectiated

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

If the matrix rows are sorted in ascending order by the actual sum, we can change the color measure to following:

 

ColorMeasure = 
VAR t =
    ADDCOLUMNS (
        GROUPBY ( ALLSELECTED ( 'Table' ), [Row] ),
        "TotalActualSum", CALCULATE ( SUM ( 'Table'[Actual] ) )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Row] )
            IN SELECTCOLUMNS ( TOPN ( 2, t, [TotalActualSum], ASC ), "RowName", [Row] ),
        IF ( SUM ( 'Table'[Actual] ) > SUM ( 'Table'[Budget] ), "#00FF00" ),
        IF ( SUM ( 'Table'[Actual] ) > SUM ( 'Table'[Budget] ), "#FF0000" )
    )

 

1.jpg

 


Best regards,

 

Community Support Team _ Dong Li
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-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

First of all, we need to group the rows and define the color you want to show.

 

 

6.PNG

 

Then we create the corol measure and use it in Condition Format.

 

ColorMeasure =
IF (
    SUM ( 'Table'[Actual] ) > SUM ( 'Table'[Budget] ),
    SWITCH ( MAX ( 'Table'[Color] ), "Green", "#00FF00", "Red", "#FF0000" )
)

 

3.PNG4.PNG5.PNG

 


Best regards,

 

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

Hey @v-lid-msft ,  So the reasoning behind why some are green and some are red is this: the first two rows are if actual > budget= green else red and the next two rows if Actual > budget = red else green. Would that be at all possible? Thanks!

Hi @Anonymous ,

 

If the matrix rows are sorted in ascending order by the actual sum, we can change the color measure to following:

 

ColorMeasure = 
VAR t =
    ADDCOLUMNS (
        GROUPBY ( ALLSELECTED ( 'Table' ), [Row] ),
        "TotalActualSum", CALCULATE ( SUM ( 'Table'[Actual] ) )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Row] )
            IN SELECTCOLUMNS ( TOPN ( 2, t, [TotalActualSum], ASC ), "RowName", [Row] ),
        IF ( SUM ( 'Table'[Actual] ) > SUM ( 'Table'[Budget] ), "#00FF00" ),
        IF ( SUM ( 'Table'[Actual] ) > SUM ( 'Table'[Budget] ), "#FF0000" )
    )

 

1.jpg

 


Best regards,

 

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

@v-lid-msft ,

Awesome! Like Magic...
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Community Champion
Community Champion

@Anonymous ,
Why would you want that?
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

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

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.