cancel
Showing results for
Did you mean:
Highlighted
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 Days Action Result 4 2 Green 6 2 Yellow 8 2 Red 15 3 Blue 16 4 Orange

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

Accepted Solutions
Highlighted
Microsoft

## Re: Calculated Column with multiple IF Else Then

@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"
)
```
5 REPLIES 5
Highlighted
Resolver II

## Re: Calculated Column with multiple IF Else Then

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.

Highlighted
Resolver I

## Re: Calculated Column with multiple IF Else Then

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

Highlighted
Microsoft

## Re: Calculated Column with multiple IF Else Then

@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"
)
```
Highlighted
Resolver I

## Re: Calculated Column with multiple IF Else Then

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

Highlighted
Microsoft

## Re: Calculated Column with multiple IF Else Then

Glad to help. 🙂

Announcements

#### Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

#### Power Platform Community Conference

Check out the on demand sessions that are available now!

#### Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

#### Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors