Forum Discussion

dommyw277's avatar
dommyw277
Helper V
3 years ago
Solved

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

 

  • Try this:

     

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

     

7 Replies

  • 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.

    • JorgePinho's avatar
      JorgePinho
      Solution Sage

      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")