cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TheRockStarDBA
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
djeepy1
Advocate I
Advocate I

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

View solution in original post

4 REPLIES 4
midhunjoy
New Member

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

 

Hope this helps

 

Thanks,

Midhun

djeepy1
Advocate I
Advocate I

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

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.

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

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors