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
analyst85
Helper I
Helper I

Custom column using IF/AND

Hello

 

I'm attempting to create a custom column based on the values of two existing columns (Score, Name) however I only get zeroes when using the below query and can't understand why?

 

if [Score = "3" and [Name] = "RT01" then "This service has alot of radios" else if [Score] = "3" and [Name] = "RT02" then "This service has less radios" else if [Score] = "3" and [Name] = "J01" then "This service has alot of jobs" else if [Score] = "3" and [Name] = "J02" then "This service has less jobs" else 0

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

The first [Score  is missing a ] but i assume that is a type.  If the Score column is numeric you need just put the number without quotes  - [Score] = 3

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

So we can see that all rows are falling through to the 'else' clause and returning 0.

If you want to debug this write a new, simple custom column with a single test - if, then, else

and try to make that work.

for example: if [Score] = "3" then "success" else "fail"

----

Looking at your code, I can guess that it may return all "fail" - see if you can make it work

mahoneypat
Employee
Employee

The first [Score  is missing a ] but i assume that is a type.  If the Score column is numeric you need just put the number without quotes  - [Score] = 3

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks, the removal of quotes helped but I only get a succesful outcome if the first IF statement is met. However if the second statement is met it doesn't work and gives me zeroes still. Is there something I need to do to ensure each statement is checked?

Nevermind it has actually worked, thanks so much!

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.

Top Solution Authors
Top Kudoed Authors