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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dataforlife
Frequent Visitor

Conditional formatting per group

I am trying to do conditional formatting per group with the following logic, but it does not seem to work.
The logic of my measure should be as follows: if group x has y amount of work, then it should be labeled either green, orange or red.
 
When I exclude the team strings, it does seem to work, but the combination of numerical logic (e.g. > 0 && < 18) and then choosing the right team seems to make the measure not work.
I am also not able to select it as a measure for my conditional formatting (only if I change the measure data type to text).

 

 

 

Color measure =
VAR Team =
    SELECTEDVALUE ( Team[Name] )
RETURN
    SWITCH (
        TRUE (),
        Team = "South"
            && 'Measures'[Work Total] >= 0
            && Measures'[Work Total] < 18, "#09D543",
        -- Green
        Team = "South,"
            && Measures'[Work Total] >= 18
            && Measures'[Work Total] < 36, "#FFA500",
        -- Orange
        Team = "South"
            && Measures'[Work Total] >= 36, "#FF0000",
        -- Red
        Team = "North"
            && Measures'[Work Total] >= 0
            && Measures'[Work Total] < 10, "#09D543",
        -- Green
        Team = "North"
            && Measures'[Work Total] >= 10
            && Measures'[Work Total] < 20, "#FFA500",
        -- Orange
        Team = "North"
            && Measures'[Work Total] >= 20, "#FF0000",
        -- Red
        Team = "West"
            && Measures'[Work Total] >= 0
            && Measures'[Work Total] <= 10, "#09D543",
        -- Green
        Team = "West"
            && Measures'[Work Total] > 10
            && Measures'[Work Total] <= 20, "#FFA500",
        -- Orange
        Team = "West"
            && Measures'[Work Total] > 20, "#FF0000",
        -- Red
        Team = "East"
            && Measures'[Work Total] >= 0
            && Measures'[Work Total] <= 10, "#09D543",
        -- Green
        Team = "East"
            && Measures'[Work Total] > 10
            && Measures'[Work Total] <= 20, "#FFA500",
        -- Orange
        Team = "East"
            && Measures'[Work Total] > 20, "#FF0000",
        -- Red
        Team = "Central"
            && Measures'[Work Total] >= 0
            && Measures'[Work Total] <= 10, "#09D543",
        -- Green
        Team = "Central"
            && Measures'[Work Total] > 10
            && Measures'[Work Total] <= 20, "#FFA500",
        -- Orange
        Team = "Central"
            && Measures'[Work Total] > 20, "#FF0000",
        -- Red
        BLANK () -- Default case
    )

 

 

 

 

 

 
For a table that includes the following information
TeamWeek 32Week 33
North59
East2134
South912
West3541
Central200150

I have also tried using if statements in my measure. The following below seems to work in general, but it does not seem to filter once I include the team logic (&& Team[Name]) = "South").
 
Who can help me out here? Thanks in advance!
 
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@dataforlife I'm confident that is a data quality issue. Please perform trim and clean steps in PQ and then check. If it still doesn't work, please share a sample pbix file, and remove sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

8 REPLIES 8
parry2k
Super User
Super User

@dataforlife I'm confident that is a data quality issue. Please perform trim and clean steps in PQ and then check. If it still doesn't work, please share a sample pbix file, and remove sensitive information before sharing.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

You're right, I tried my dax function in a test table and it works. I'll have to see what goes wrong in the column "team'' and I'll try the clean and trim.

parry2k
Super User
Super User

@dataforlife one another reason could be that team name has some non printable characters that are not visible and the comparison is not happening. Just guessing, may be clean and trim the team name column data in PQ to clear all spaces and non printable characters. Again this is just a wild guess.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@dataforlife if you put the measure in a table visual with team[name] column, do you see "green" or "Red" color. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

No, it does not color any of the fields. I tried 

 

Measure Teamcolor = if(SELECTEDVALUE(Team[Name]) = "South", "Green", "Red")

 

just to check whether it will color any of the rows that belong to Team south, but it does not do it.

chonchar
Helper V
Helper V

@dataforlife 

Hello. I am new here and by no means an expert. But you can conditionally format values following the prompts in the screen shot below. Right click the measure from the matrix> conditional formatting>background color> and edit the rules. You can enter <,>,=, is, start with, etc as the rule and edit the hex code for each value. 

 

Hope this helps. 

 

 

chonchar_0-1692716348894.png

 

parry2k
Super User
Super User

@dataforlife it should work, just to make sure, the column for Team you are using on the rows is the one you are checking in the measure, I'm sure that is the case but just double checking.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I tried debugging whether it is able to find the team and color, but it does not seem to work. It simply does not do anything. Do you have an idea why? The dax function does not color any field.

Example code:

 

 

Measure Teamcolor = if(SELECTEDVALUE(Team[Name]) = "South", "Green", "Red")

 

 



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.