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
dommyw277
Helper II
Helper II

Nested IF statements not working

Hi, 

Im trying to create a new column based on 3 queries? I basically want to say if it contains this then bring back that:

So if it contains 123 its Test1, 456 its Test 2 else Test 3

 

NewColumnName =
IF(
'NewColumnName'[SERVICE_TYPE] = 123,
"Test1",
IF(
'NewColumnName'[SERVICE_TYPE] = 456,
"Test2",
"Test3"
)
)

 

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Try this:

 

NewColumnName =
IF(
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE], "123"),
"Test1",
IF(
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE],"456"),
"Test2",
"Test3"
)
)

 

View solution in original post

7 REPLIES 7
dommyw277
Helper II
Helper II

Amazing, thank you!

You're welcome @dommyw277 🙂

I would also suggest you to use SWITCH instead of nested IFs:

NewColumnName =
SWITCH(TRUE(),
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE], "123"),"Test1",
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE],"456"),"Test2",
"Test3")


 

JorgePinho
Solution Sage
Solution Sage

What is the type of the column SERVICE_TYPE? Is it Text or Numeric? If it is text you are treating it as a numeric.

Hi, yes its Text - it contains text and numbers?

@dommyw277 can you give an example of the values in that column?

Thanks. Heres a brief example:

cd6b6eec- Azure

0b4c205 - AZURE 2

Try this:

 

NewColumnName =
IF(
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE], "123"),
"Test1",
IF(
CONTAINSSTRING('NewColumnName'[SERVICE_TYPE],"456"),
"Test2",
"Test3"
)
)

 

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.