Forum Discussion
Create new Column Using Conditions from multiple other columns
- 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
Hi Swiftojo,
Thank you for reaching out to the Microsoft Fabric Community Forum.
I’ve reproduced your scenario in Power BI Desktop based on the logic you provided. I created sample data and implemented a calculated column using DAX to flag rows according to the specified conditions.
I’ve validated the logic and received the expected output, matching your requirements:
The DAX used for the calculated column:
Flag =
SWITCH(TRUE(),
CONTAINSSTRING([Column A], "Info A"), "Info A",
CONTAINSSTRING([Column A], "Info B"), "Info B",
[Column B] = "Type 1", "Info",
[Column C] = "Type 1" && [Column B] <> "Type 1", "Info",
BLANK()
)
For your convenience, I’ve attached the .pbix file used for testing this scenario. Feel free to explore and modify it further as per your dataset.
Thanks kushanNa & SamsonTruong for sharing your valuable insights.
If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.