cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dooriya101
Frequent Visitor

Multiple conditions in SWITCH ()

Hi Team,

 

I have a Case Table and Priority Table, and have a column chart to show average of Time, and have another DAX code to have colour settings like if actual time is within 50% of target time, then show green, if within 80% then yellow, else red.

 

So it looks like:

 

Pirority = "A" && Actual time <= 2*1.5, "Green",

Pirority = "A" && Actual time <= 2*1.8, "Yellow",

Pirority = "A" && Actual time > 2*1.8, "Red",

Pirority = "B" && Actual time <= 4*1.5, "Green",

Pirority = "B" && Actual time <= 4*1.8, "Yellow",

Pirority = "B" && Actual time > 4*1.8, "Red",

Pirority = "C" && Actual time <= 6*1.5, "Green",

Pirority = "C" && Actual time <= 6*1.8, "Yellow",

Pirority = "C" && Actual time > 6*1.8, "Red",

Pirority = "D" && Actual time <= 8*1.5, "Green",

Pirority = "D" && Actual time <= 8*1.8, "Yellow",

Pirority = "D" && Actual time > 8*1.8, "Red",

 

I'm wondering if this is right logic and if there is any simple way to write this? Thanks!

 

Priority Table

PriorityTarget Time
A2
B4
C6
D8

 

Case Table:

Case IDPriorityActual Time
001A1.5
002B4.8
003D22.2
004A0.7
005A5.5
006B3.3
007C6.1
008C2.4
009A2.2
010B9
2 REPLIES 2
amitchandak
Super User
Super User

@Dooriya101 , Hope both tables are joined. You have to create a measure like, You can add additional conditions as per need

 

var _a = sum(Table2[Actual time])
var _p = Max(Table[Pirority])
return
Switch( True()
_= "A" && _a<= 2*1.5, "Green",
_= "A" && _a<= 2*1.8, "Yellow",
_= "A" && _a> 2*1.8, "Red"
// add other
)

 

How to do conditional formatting by measure and apply it on pie?
https://www.youtube.com/watch?v=RqBb5eBf_I4&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L
https://community.powerbi.com/t5/Community-Blog/Power-BI-Conditional-formatting-the-Pie-Visual/ba-p/...
https://amitchandak.medium.com/power-bi-where-is-the-conditional-formatting-option-in-new-format-pan...

Hi Amitchandak, thenks for you reply and link provided. I've created DAX code as your advised, but when I try to apply in column chart, it doesn't allow me to choose it.

 

 

 

Below are my codes in product environment:

 

var _a = sum('SLA Closed'[SLA Response Duration (in Hours)])
var _p = Max('Priority - SLA Response Target Hours'[Priority])
return
Switch(
    True(),
    _a= "Critical" && _a<= 2*1.05, "Green",
    _a= "Critical" && _a<= 2*1.08, "Yellow",
    _a= "Critical" && _a> 2*1.08, "Red",
    _a= "High" && _a<= 4*1.05, "Green",
    _a= "High" && _a<= 4*1.08, "Yellow",
    _a= "High" && _a> 4*1.08, "Red",
    _a= "Medium" && _a<= 8*1.05, "Green",
    _a= "Medium" && _a<= 8*1.08, "Yellow",
    _a= "Medium" && _a> 8*1.08, "Red",
    _a= "Low" && _a<= 16*1.05, "Green",
    _a= "Low" && _a<= 16*1.08, "Yellow",
    _a= "Low" && _a> 16*1.08, "Red")
 
Thanks!

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors