cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## Implement CASE statement just like TSQL in PowerBI

Hello,

Is there a way to implement below case statement as a measure or a new column in powerBI

Result = case when AVG_USER_ACTIVE < 10 and PercentUsage < 20.00 and Total > 180 then 1

else 0

end

I have looked into switch and IF but getting syntax error.

Thanks,

Kin

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Implement CASE statement just like TSQL in PowerBI

Maybe I haven't understood but uou can use a simple if :

result = if AVG_USER_ACTIVE < 10 and PercentUsage < 20.00 and Total > 180 then 1 else 0

And you can nest them :

result = if 1=1 and 1<>2 then

if 1<2 then 1 else 0

else 0

Use parenthesis to priorize and clarify.

Jean-Pierre Riehl

Jean-Pierre Riehl
MVP Data Platform
4 REPLIES 4

## Re: Implement CASE statement just like TSQL in PowerBI

Maybe I haven't understood but uou can use a simple if :

result = if AVG_USER_ACTIVE < 10 and PercentUsage < 20.00 and Total > 180 then 1 else 0

And you can nest them :

result = if 1=1 and 1<>2 then

if 1<2 then 1 else 0

else 0

Use parenthesis to priorize and clarify.

Jean-Pierre Riehl

Jean-Pierre Riehl
MVP Data Platform
Frequent Visitor

## Re: Implement CASE statement just like TSQL in PowerBI

Thanks ! I created a custom column with what you suggested and now its working.

Just a note for future readers: You cannot create a measure as I thought I could initially and hence this question.

## Re: Implement CASE statement just like TSQL in PowerBI

You can create a Measure or a Calculated Column with that logic. You just need to write it in DAX.

In DAX, IF() is a function and logical operators are && (AND) and || (OR).

(there are also AND() / OR() functions but it is less readable)

Here is the syntax :

= IF([AVG_USER_ACTIVE] < 10 && [PercentUsage] < 20.00 && [Total] > 180 ; 1 ; 0)

Notice the brackets [] to reference a Column or another Measure.

You can nest IF() functions in second and third parameters

In DAX, you also have the SWITCH function if you want different results with different inputs.

Jean-Pierre Riehl
MVP Data Platform
New Member

## Re: Implement CASE statement just like TSQL in PowerBI

Result = if(AVG_USER_ACTIVE < 10,if (PercentUsage < 20.00,if (Total > 180,1,0)),0)

Hope this helps

Thanks,

Midhun

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors