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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Power BI if statement / replace

How do I replace whole cells in a column if few of those cells contain a specific text along with other words. As you can see from the picture, I am trying to replace all the cells that contain the word DUCTWORK (highlighted) with HVAC, and would like to replace all the content in that cell with it (HVAC). i.e, If cell contains the word ductwork, replace whole cell with hvac.

 

Thank you

 

memad_1-1642772809910.png

 

1 ACCEPTED SOLUTION
Resty
Frequent Visitor

Hi,

please insert next step that will use this:

 

= Table.TransformColumns(NameOfPreviousStep, {{"Sheet Name - Copy", each if Text.Contains(_, "DUCTWORK") then "HVAC" else _ }})

 

just make sure that you will replace NameOfPreviousStep with your previous steps name.

Hope it helps!

View solution in original post

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

May I ask if your problem has been solved? Is the above post helpful to you?

If  it does, could you please mark the post which help as Answered? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.

 

Based on my research, the formula provided by @Resty  will work for you
Result:

vangzhengmsft_0-1643096486113.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

jennratten
Super User
Super User

There are a couple of enhancements that may be helpful to include in your script - please see below.

If you start with these values (note, row 2 includes DUCTWORK but it is lowercase):

 

jennratten_3-1642796069809.png

 

Option 1 - replacements are case sensitive and the resulting column is not of type text:

Table.TransformColumns(#"Changed Type", {{"Sheet Name - Copy", each if Text.Contains(_, "DUCTWORK") then "HVAC" else _}})

Replaces instances in which the keyphrase with matching case is found. The result also returns type any instead of type text, creating an additional step for you to change back to text.

 

jennratten_4-1642796094488.png

 

 

Option 2 - make the replacements perform without case sensitivity and the resulting column is of type text.

Returning the column as text is done by specifying "type text" as the third argument inside of the transformation function.

Performing the replacements with case insensitivity is done by specifying "Comparer.OrdinalIgnoreCase" as the third argument inside of the Text.Contains function.

Table.TransformColumns(#"Changed Type", {{"Sheet Name - Copy", each if Text.Contains(_, "DUCTWORK", Comparer.OrdinalIgnoreCase) then "HVAC" else _, type text}})

 

jennratten_5-1642796300865.png

 

 

Resty
Frequent Visitor

Hi,

please insert next step that will use this:

 

= Table.TransformColumns(NameOfPreviousStep, {{"Sheet Name - Copy", each if Text.Contains(_, "DUCTWORK") then "HVAC" else _ }})

 

just make sure that you will replace NameOfPreviousStep with your previous steps name.

Hope it helps!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors