Forum Discussion

sw123's avatar
sw123
Helper III
2 years ago
Solved

New column with values based on another column

Hi,

I want to add a new column (B) based on another column (A). If the text string in Column A starts with either 1, N1, S1 or I1, column B should be textstring “C”. If the text string in Column A starts with either 2, N2, S2 or I2, column B should be textstring “D”. And so on. How do I do this?

Thankful for help!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi sw123 ,

     

    can you check with below dax experssion:

    NewColumn =
    SWITCH(
        TRUE(),
        LEFT(Job_List[Description], 3) = "A &" || LEFT(Job_List[Description], 2) = "N1" || LEFT(Job_List[Description], 2) = "S1" || LEFT(Job_List[Description], 2) = "I1", "C",
        LEFT(Job_List[Description], 1) = "2" || LEFT(Job_List[Description], 2) = "N2" || LEFT(Job_List[Description], 2) = "S2" || LEFT(Job_List[Description], 2) = "I2", "D",
        // Add more conditions as needed
        "Other"
    )

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sw123 ,

     

    can you check with below dax experssion:

    NewColumn =
    SWITCH(
        TRUE(),
        LEFT(Job_List[Description], 3) = "A &" || LEFT(Job_List[Description], 2) = "N1" || LEFT(Job_List[Description], 2) = "S1" || LEFT(Job_List[Description], 2) = "I1", "C",
        LEFT(Job_List[Description], 1) = "2" || LEFT(Job_List[Description], 2) = "N2" || LEFT(Job_List[Description], 2) = "S2" || LEFT(Job_List[Description], 2) = "I2", "D",
        // Add more conditions as needed
        "Other"
    )