Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Swiftojo
Regular Visitor

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 Contains "Info B", insert "Info B" in new Column AND

Where Column B = "Type 1", Insert "Info" in new column AND

Where Column C = "Type 1" AND Column B <> "Type 1", Insert "Info" into new column

where it does not meet any of this criteria, leave blank

 

So I end up with a column that has flagged certain rows if they meet this criteria.

 

Would I do a calculated column here, or create a new column - and what would the DAX be?

 

Thanks in advance!

1 ACCEPTED SOLUTION
SamsonTruong
Impactful Individual
Impactful Individual

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



View solution in original post

5 REPLIES 5
v-ssriganesh
Community Support
Community Support

Hi @Swiftojo,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

Thank you everyone.  This solution worked!

v-ssriganesh
Community Support
Community Support

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:

vssriganesh_0-1747990507823.png

 

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.

kushanNa
Solution Sage
Solution Sage

Hi @Swiftojo 

 

you can use the calculated column 

 

try using following code ? 

 

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

 

eg:

 

kushanNa_0-1747977214345.png

 

SamsonTruong
Impactful Individual
Impactful Individual

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



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.