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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
ashmitp869
Responsive Resident
Responsive Resident

Help needed in dax expression - for Conditional Formating for background color.

Hi All,

 

Help needed for  Conditional Formating for background color.

 

My requirement :

 

=if(Len([PTD - Revenue Accrual (Ex-GST)])>0 and [PTD - Revenue Accrual (Ex-GST)]<>'-', if([PTD - Revenue Accrual (Ex-GST)]>([MTD Total - Revenue (Ex-GST)]*.3),RGB(255,199,206)) )

 

 

My expression:

 

 

PTD - Revenue Accrual Color = SWITCH( TRUE(), AND( LEN([PTD - Revenue Accrual(Ex-GST)]) > 0, [PTD - Revenue Accrual(Ex-GST)] <> "-" ), IF( [PTD - Revenue Accrual(Ex-GST)] > ([MTD Total - Revenue(Ex-GST)] * 0.3), "#FFC7CE" // This is a hex color code for a shade of red ), BLANK() )

 

 

Help me with the expression . When using RETURN key word its giving me error.

 

ashmitp869_0-1723605052970.png

 

1 ACCEPTED SOLUTION
ashmitp869
Responsive Resident
Responsive Resident

Thanks for the help..

PTD - Revenue Accrual Color =  
SWITCH(
        TRUE(),
        AND(
            LEN([PTD - Revenue Accrual(Ex-GST)]) > 0, 
            [PTD - Revenue Accrual(Ex-GST)] <> BLANK()
        ),      IF(
            [PTD - Revenue Accrual(Ex-GST)] > ([MTD Total - Revenue(Ex-GST)] * 0.3), 
           "#FFC7CE"  // This is a hex color code for a shade of red
        ),
        BLANK()
    )

instead of "-" I used Blank() 

View solution in original post

7 REPLIES 7
Irwan
Super User
Super User

hello @ashmitp869 

 

you use RETURN when you are using VAR.

if there is no VAR in prior to, then no need to put RETURN.

Thank you.

ashmitp869
Responsive Resident
Responsive Resident

Thanks for the explanation @Irwan .

 

But do you know why my expression is not working ?

hello @ashmitp869 

 

i suspect because of that RETURN, no?

Have you tried deleting that RETURN command? let see if your DAX still not working even after deleting RETURN.


thank you.

ashmitp869
Responsive Resident
Responsive Resident

I remove the RETURN but still not working

hello @ashmitp869 

 

Irwan_1-1723609592731.png

 

i dont know what your dataset looks like, but here are what i found: 

1. Line 6 shows LEN which is used for string length, is [PTD - Revenue Accrual(Ex-GST)] a string or number?

2. i assumed [PTD - Revenue Accrual(Ex-GST)] is a string since you are comparing to string value in Line 7.

3. however, in Line 10, you are comparing [PTD - Revenue Accrual(Ex-GST)] and [MTD Total - Revenue(Ex-GST)] as number format (integer)

Irwan_2-1723609827319.png

i tried to replicate your data, as you can see the error says you can not compare integer and text together.

 

if this doesnt solve your issue, please provide your sample data (removing all confidential information).

 

Hope this will help.

Thank you.

ashmitp869
Responsive Resident
Responsive Resident

Thanks for the help..

PTD - Revenue Accrual Color =  
SWITCH(
        TRUE(),
        AND(
            LEN([PTD - Revenue Accrual(Ex-GST)]) > 0, 
            [PTD - Revenue Accrual(Ex-GST)] <> BLANK()
        ),      IF(
            [PTD - Revenue Accrual(Ex-GST)] > ([MTD Total - Revenue(Ex-GST)] * 0.3), 
           "#FFC7CE"  // This is a hex color code for a shade of red
        ),
        BLANK()
    )

instead of "-" I used Blank() 

glad it is solved.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors