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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
BBIUser
Helper IV
Helper IV

How to use the CASE statement in Power BI?

Hi,

 

1) How do I convert the below CASE statement to DAX in Power BI? 

 

case when cCount > 0 and ThreeYrAvg > 0
then
case
when cCount - ThreeYrAvg >= 5
and round( ( ( cCount * 1.00 - ThreeYrAvg ) / ThreeYrAvg) * 100, 2 ) >= 10.00
then 'Increase'
when cCount - ThreeYrAvg <= -5
and round( ( ( cCount * 1.00 - ThreeYrAvg ) / ThreeYrAvg ) * 100, 2 ) <= -10.00
then 'Decrease'
else 'None' end
else 'None'
end "Notable Change?",

 

Column 1 = cCount

Column 2 = ThreeYrAvg from Table A.

 

I want to create a calculated 'Column' named = "Notable Change?" which will have Increase, Decrease and None values in the new column (from the CASE statement).

 

2) and then a calculated 'Measure'. Calculated 'Measure' should show just the record count of "Increase and Decrease" which I then show it using a 'Card' visualization.


Do I need to use 'Switch' DAX expression?

 

Appreciate your inputs!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @BBIUser,

I've created a sample data and used custom column to use -IF-ELSE-IF statements to get the result you need as shown below in images.

 

1.PNG

-------------------------------------------------------------- 

2.PNG

--------------------------------------------------------- 

3.PNG

Let me know if any doubt persists.

Thanks and Regards,

Piyush 

 

View solution in original post

5 REPLIES 5
EllaGen
New Member

hi i want to do a case statement in powerbi that is coming from a culculated measure in Power bi , how do i do this

Numbers% = sum(Query1[NuberPas])/sum(Query1[AllAssessed]) > this is the calculated measure but i want to do a calculated measure with this calculation 
 
 
New Calculated meature from top 1
Case when Numbers% = 100 then 1 else 0 end as NumberPositive

 

 

thanking you in advance

Anonymous
Not applicable

HI @BBIUser,

I've created a sample data and used custom column to use -IF-ELSE-IF statements to get the result you need as shown below in images.

 

1.PNG

-------------------------------------------------------------- 

2.PNG

--------------------------------------------------------- 

3.PNG

Let me know if any doubt persists.

Thanks and Regards,

Piyush 

 

Thanks @Anonymous! It works.

 

Since I am new to Power BI and only trying out POCs, it is good to know that there is an option 'Custom Column'.

But can I know in what scenarios the 'custom column' and 'calculated column' should be used?

 

Thanks again!

 

 

Greg_Deckler
Super User
Super User

Yes, SWITCH funtion is your equivalent or nested IF statements. Give me some sample data to play with and can be more specific. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...



@Greg_Deckler My apologizes if my question was not clear and for not posting the sample data.

Here is the sample data.    

 2018-05-04_1500.png

Here cCount is "Current Year",
pCount is "Prior Year",
p1Count is "Current Year-2",
p2Count is "CurrentYear-3"

ThreeYrAvg is "3 Year Avg"

 

With the CASE statement I want to add another calculated column and a measure. Please let me know if it is more clear with the sample data. Thanks for your help!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.