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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
drrai66
Resolver I
Resolver I

Calculated Column with multiple IF Else Then

Hi All,

I have two calculated Columns which I created in the Data view from other Columns. The Calculated Columns are [Number of Days] and [Action]

 

Number of DaysActionResult
42Green
62Yellow
82Red
153Blue
164Orange

 

I want to Have another Calculated Column , [Result]in the Data based upon following conditions;

If [Number of Days]<=5 and Action<=2 THEN Green

ELSE IF [Number of Days]>5 and  [Number of Days]<8 and Action<=2 THEN Yellow

ELSE IF [Number of Days]>=8 and Action<=2 THEN Red

ELSE IF [Number of Days]<=15 and Action<=3 THEN BLUE

ELSE IF [Number of Days]>15 and Action>3 THEN Orange

ELSE Violet

END

 

Please Help in writing the above to get [Result] Column values

Thanks

Deepak

1 ACCEPTED SOLUTION

@drrai66

The DAX is like

Column =
SWITCH (
    TRUE (),
    yourTable[Number of Days] < 5
        && yourTable[Action] <= 2, "Green",
    yourTable[Number of Days] < 8
        && yourTable[Action] <= 2, "Yellow",
    yourTable[Number of Days] >= 8
        && yourTable[Action] <= 2, "Red",
    yourTable[Number of Days] <= 15
        && yourTable[Action] <= 3, "blue",
    yourTable[Number of Days] >= 15
        && yourTable[Action] > 3, "Orange",
    "Violet"
)

View solution in original post

7 REPLIES 7
srinivt
Microsoft Employee
Microsoft Employee

You can use IF and SWITCH function in DAX to do this. You can either use nested IFs (which should map pretty easily for your sample condition) or SWITCH with first parameter as TRUE and each condition representing an arbitrary condition expression. 

Hi SRINIVT,

I am Totally new to Power BI and I am stuck on this. Can you please do one more favour and write the Formula. I had tried earlier but could not do, so I posted here.

Thanks

Deepak

@drrai66

The DAX is like

Column =
SWITCH (
    TRUE (),
    yourTable[Number of Days] < 5
        && yourTable[Action] <= 2, "Green",
    yourTable[Number of Days] < 8
        && yourTable[Action] <= 2, "Yellow",
    yourTable[Number of Days] >= 8
        && yourTable[Action] <= 2, "Red",
    yourTable[Number of Days] <= 15
        && yourTable[Action] <= 3, "blue",
    yourTable[Number of Days] >= 15
        && yourTable[Action] > 3, "Orange",
    "Violet"
)

Anuja_Chaudhari_0-1705477528730.png

 

Hi, 

Hope this helps.

Capture4.PNG

Thanks and Many Many Thanks. Learnt something new from you and Solved my Problem. I used your Formula at Many many places in my dataset and it works like Charm!!!

Thanks

Deepak

Glad to help. 🙂

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.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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