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
Anonymous
Not applicable

Power Query to replace multiple columns with different values based on another column value

Power Query to replace multiple columns with different values based on another column value.  I am only able to execute one replace value in power query.  I have these two examples below:

 

#"Replaced A" = Table.ReplaceValue(#"Changed Type", each [A], each if Text.Contains([D], "Value1") then "SomeNew1" else [A],Replacer.ReplaceText, {"A"}),
#"Replaced B" = Table.ReplaceValue(#"Changed Type", each [B], each if Text.Contains([D], "Value1") then "SomeNew2" else [B],Replacer.ReplaceText, {"B"})

#"Replaced C" = Table.ReplaceValue(#"Changed Type", each [C], each if Text.Contains([D], "Value1") then "SomeNew3" else [C],Replacer.ReplaceText, {"C"})

 

How can I combined all 3 replace statement into one since each individual replace can't work.  When I enter all 3 replace conditions, only the last one works.

 

 

 

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Anonymous Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Current data

kd3835_1-1629679797456.png

 

Greg, thank you for quick. I a beginner to power bi so I will try to explain to best as I can.  I want to be able search text like "Delivery" from column (Condition Reason) and replace those other columns highlighted in yellow with different values as shown.

 

I can get UNIT column to change as follow:

 

Table.ReplaceValue(#"Changed Type", each [UNIT], each if Text.Contains([Condition Reason], "Delivery") then "SelfService" else [UNIT],Replacer.ReplaceText, {"UNIT"}),

 

But when I try to have multiple replace value, it will only replace the last value in M code.

 

This is the final result I am trying to achieve.

 

kd3835_2-1629679850568.png

 

Any suggestion?

@Anonymous Please paste sample data as text so that can copy and paste easily to test out different methods.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

This is current data that I am trying to convert.

Status Condition Reason Unit Dept
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess DediccatedServiceHR
UNKNOWNTroubleshooting: Request-Agent-DeliveryGateway::DeliveryGateway DediccatedServiceFinance
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess SelfService Finance
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess SelfService Finance
UNKNOWNTroubleshooting:NewTask::Deliverylneligible UNKNOWNFinance
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess SelfService HR
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess SelfService Finance
UNKNOWNTroubleshooting:NewTask::DeliveryOrderSuccess SelfService Finance
UNKNOWNTroubleshooting: Request-Agent-DeliveryGateway::DeliveryGateway SelfService Finance

 

I want to convert the data into this based on search criteria on column (Condition Reason)

 

Status Condition Reason Unit Dept
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Failed Troubleshooting: Request-Agent-DeliveryGateway::DeliveryGateway SelfService TechSupport 
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Failed Troubleshooting:NewTask::Deliverylneligible SelfService TechSupport 
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Success Troubleshooting:NewTask::DeliveryOrderSuccess SelfService TechSupport 
Failed Troubleshooting: Request-Agent-DeliveryGateway::DeliveryGateway SelfService TechSupport 

 

I have tried this but it only allow me to convert the last one only.

 

Replaced Unit" = Table.ReplaceValue(#"Changed Type1", each [Unit], each if Text.Contains([Condition Reason], "DropShip") then "SelfService" else [Unit],Replacer.ReplaceText, {"Unit"})
Replaced Dept" = Table.ReplaceValue(#"Changed Type1", each [Dept], each if Text.Contains([Condition Reason], "DropShip") then "TechSupport" else [Dept],Replacer.ReplaceText, {"Dept"})

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.