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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Rup10
Resolver I
Resolver I

Custom column by using switch case

Hi,

I have to add a custom column called"Data" by using below switch case : 

CASE
WHEN Ratio <= 0.05 THEN 5
WHEN (Ratio > 0.05) and (Ratio <= 0.1) THEN 4
WHEN (Ratio > 0.1) and (Ratio <= 0.2) THEN 3
WHEN (Ratio > 0.2) and (Ratio <= 0.3) THEN 2
WHEN Ratio > 0.3 THEN 1
END

Can someone please me with this.

Thanks.

2 ACCEPTED SOLUTIONS

Hi @Rup10 

Try this

 

Score = SWITCH( TRUE(), 

                [Nonstandard_Ratio] <= 0.05, 5,

                AND([Nonstandard_Ratio] > 0.05, [Nonstandard_Ratio] <= 0.1), 4,

                AND([Nonstandard_Ratio] > 0.1, [Nonstandard_Ratio] <= 0.2), 3,

                AND([Nonstandard_Ratio] > 0.2, [Nonstandard_Ratio] <= 0.3), 2,

                [Nonstandard_Ratio] > 0.3,1

)

 

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

Hi @PhilipTreacy ,

Thank you so much.It worked.

View solution in original post

4 REPLIES 4
Rup10
Resolver I
Resolver I

Hi @amitchandak ,

I am getting this below error.

Note : In the below image i have used Nonstandard_Ratio(because that is my column name) instead of Ratio

Rup10_0-1605604610779.png

Thanks.

 

Hi @Rup10 

Try this

 

Score = SWITCH( TRUE(), 

                [Nonstandard_Ratio] <= 0.05, 5,

                AND([Nonstandard_Ratio] > 0.05, [Nonstandard_Ratio] <= 0.1), 4,

                AND([Nonstandard_Ratio] > 0.1, [Nonstandard_Ratio] <= 0.2), 3,

                AND([Nonstandard_Ratio] > 0.2, [Nonstandard_Ratio] <= 0.3), 2,

                [Nonstandard_Ratio] > 0.3,1

)

 

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy ,

Thank you so much.It worked.

amitchandak
Super User
Super User

@Rup10 , Try Switch, Create a new column 

 

Switch( True()
[Ratio] <= 0.05 , 5,
([Ratio] > 0.05) && ([Ratio] <= 0.1) , 4,
([Ratio] > 0.1) && ([Ratio] <= 0.2) , 3,
([Ratio] > 0.2) && ([Ratio] <= 0.3) , 2,
[Ratio] > 0.3 , 1
)

 

refer video : https://www.youtube.com/watch?v=gelJWktlR80

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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