Forum Discussion

Swiftojo's avatar
Swiftojo
Regular Visitor
1 year ago
Solved

Create new Column Using Conditions from multiple other columns

Very new to Power BI here.   I want to create a new column that is a  bit of a flag based on other columns   where Column A Contains "Info A", insert "Info A" in new column AND where Column A Co...
  • SamsonTruong's avatar
    1 year ago

    Hi Swiftojo , a calculated column would be a good option here. The DAX SWITCH function would be a perfect candidate for your use case. How a SWITCH function works is it evaluates multiple conditions and returns a value based on the condition met. This is similar to using nested IF statements, however it can reduce query complexity and make it much more readible.

    Here is an example DAX for your use case:

    Column =
    SWITCH(
    TRUE(),
    CONTAINSSTRING('TableName'[Column A], "Info A"), "Info A",
    CONTAINSSTRING('TableName'[Column A], "Info B"), "Info B",
    'TableName'[Column B] = "Type 1", "Info",
    'TableName'[Column C] = "Type 1" && 'TableName'[Column B] <> "Type 1", "Info",
    BLANK()
    )

     

    If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

    Thanks,

    Samson