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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
park
Frequent Visitor

Moving values to a new column based on another column

Hi.

 

Consider the situation. I have column CompanyName that are associated with rows of another coumn called Type. These are "Chain" ,"NF", "FF", and "DF"

 

CompanyNameType
WalmartChain
CostscoNF
PublixNF
BarFF

 

 

Consider that Costco and Publix are both Chains, but read as NF. Which is wrong.

 

How do I create a calculated column or expression that places these names into the right Type, "Chain." This is going to be on a large scale of data with multiple other company names as well.

 

Thank you! 

1 ACCEPTED SOLUTION

Hi @park ,

 

The above code won't work with approximate matches. Try this one instead:

tomfox_0-1661976902842.png

 

Here the code:

if Text.Contains([CompanyName], "Publix") or Text.Contains([CompanyName], "Costco") then "Chain" else [Type]

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

6 REPLIES 6
tackytechtom
Super User
Super User

Hi @park ,

 

Maybe something like this?

tomfox_4-1661975593771.png

 

 

You could create a nested if statement with all your conditions. Here an example

tomfox_0-1661975122761.png

 

tomfox_3-1661975537728.png

 

 

Here the code:

if [CompanyName] = "Publix" or [CompanyName] = "Costco" then "Chain" else [Type]

 

Alternatively, you could create an own mapping table according to your definition and then you merge the mapping table with your large table on CompanyName.

 

Let me know if this helps! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thanks! This look like it might work. I will try in a second 🙂

Will this work for approximate matches too? Like lets say I have Publix #1 - Publix #100

thanks! 

Hi @park ,

 

The above code won't work with approximate matches. Try this one instead:

tomfox_0-1661976902842.png

 

Here the code:

if Text.Contains([CompanyName], "Publix") or Text.Contains([CompanyName], "Costco") then "Chain" else [Type]

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you! And if I have lets say 20 different company names, I can continue the OR statement as many times as needed? Or does it only work for two arguments 

Hi @park ,

 

This should work for as many arguments. Please keep in mind that someone needs to update that code in case new companies are added. A better way would probably be to fix that data issue in the source itself (just saying 🙂 )

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you for the solution. This works great ! 🙂

 

Is this argument case sensitive as well? If so, is there a way to get around? 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors