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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Conditional formatting based on multiple conditions in Pivoted Data

Hi ,

Currently working on a conditional formatting logic , but stuck with the same to have the conditional formatting on Profit Colum with multiple conditions in a Pivoted Data

Requirement :- 

Apply conditional Formatting on Profit% based on the Actual and Target

i.e Conditional Formatting =
Var a = SELECTEDVALUE('Table'[Attribute])
VAR B= SELECTEDVALUE('Table'[Value])
VAR C= CALCULATE(SUM'Table'[Value]),FILTER('Table','Table'[Attribute]="Actual"))
VAR D=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Attribute]="Target"))
RETURN SWITCH(TRUE(),
a="Profit%" && C=0 ,"Red",
a="Profit%" && D=0 ,"Orange")

 

** The data will be in Pivoted form and need to build logic on the same

Sample Data

AreaGeographyAttributeValues
GermanyEuropeActual100
GermanyEuropeTarget0
GermanyEuropeProfit%40
AustraliaOceaniaActual0
AustraliaOceaniaTarget99
AustraliaOceaniaProfit%23

 

 

Regards,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

I changed to your measure to the following, then it can work, you can refer it.

Measure =
VAR a =
    SELECTEDVALUE ( 'Table'[Attribute] )
VAR B =
    SELECTEDVALUE ( 'Table'[Value] )
VAR C =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Attribute] = "Actual"
                && [Area] IN VALUES ( 'Table'[Area] )
        )
    )
VAR D =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Attribute] = "Target"
                && [Area] IN VALUES ( 'Table'[Area] )
        )
    )
RETURN
    SWITCH (
        TRUE (),
        a = "Profit%"
            && C = 0, "Red",
        a = "Profit%"
            && D = 0, "Orange"
    )

vxinruzhumsft_0-1697163150507.png

 

Best Regards!

Yolo Zhu

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 

I changed to your measure to the following, then it can work, you can refer it.

Measure =
VAR a =
    SELECTEDVALUE ( 'Table'[Attribute] )
VAR B =
    SELECTEDVALUE ( 'Table'[Value] )
VAR C =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Attribute] = "Actual"
                && [Area] IN VALUES ( 'Table'[Area] )
        )
    )
VAR D =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Attribute] = "Target"
                && [Area] IN VALUES ( 'Table'[Area] )
        )
    )
RETURN
    SWITCH (
        TRUE (),
        a = "Profit%"
            && C = 0, "Red",
        a = "Profit%"
            && D = 0, "Orange"
    )

vxinruzhumsft_0-1697163150507.png

 

Best Regards!

Yolo Zhu

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

Anonymous
Not applicable

Thanks @Deepak_22  still the logic doesnot work , have attached sc for reference , as for both the conditions , the background is red instead red & Orange

Rocker07_0-1697108241255.png

 

Deepak_22
Helper I
Helper I

Hi @Anonymous,  there are some corrections needed in the logic you provided:
It seems you missed a parenthesis in the CALCULATE function for both variable C and D

In the SWITCH function, DAX does not directly support using the && operator. Instead, you should use the AND function.

 

Here's the corrected DAX for your conditional formatting:

Color Format = 
VAR a = SELECTEDVALUE('Table'[Attribute])
VAR B = SELECTEDVALUE('Table'[Values])  -- Corrected the column name here from Value to Values
VAR C = CALCULATE(SUM('Table'[Values]), FILTER('Table', 'Table'[Attribute] = "Actual"))
VAR D = CALCULATE(SUM('Table'[Values]), FILTER('Table', 'Table'[Attribute] = "Target"))
RETURN 
    SWITCH(TRUE(),
        AND(a = "Profit%", C = 0), "Red",
        AND(a = "Profit%", D = 0), "Orange",
        BLANK()
    )

After creating the Color Format measure, go to your table visual where you wish to apply the conditional formatting.
Select the column you want to format (in this case, the "Values" column representing the Profit%).
Click on the drop-down arrow next to the column and choose "Conditional formatting" > "Font color" (or "Background color", depending on your need).
Choose "Format by field value", and in the dialog box, pick the "Color Format" measure you just created.
Apply the changes, and your table should now color the cells in the "Values" column for "Profit%" according to the conditions provided.
This will apply the conditional formatting to the Profit% based on the Actual and Target values.

 

If you find this helpful, please provide a kudo and mark it as an accepted solution.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.