cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Replace value in Power Query based on condition

Dear all,

 

I have a table ("POs") with a list of POs which have some fields that in very specifics moments have wrong entry inputs. For example in the following table the PO "1006" should have the Category "C" instead of the Category "D":

 

PO Category Amount
1001 A 1050
1002 A 1327
1003 B 1276
1004 B 1383
1005 C 1967
1006 D 1288
1007 E 1707
1008 F 1233

 

I tried to use the ReplaceValue option in Power Query but it replaces all the the Categories "D" of all the "POs". I just want to replace the category of the PO "1006".

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

HI @JoaoMS,

You can use replace value function with custom expression to add conditions to replace value steps:

    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Category],each if [PO]=1006 and [Category]="D" then "C" else [Category],Replacer.ReplaceText,{"Category"})

15.png

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
Highlighted
Super User IV
Super User IV

@JoaoMS , Something like this

if [PO] = "1006" then Text.Replace([Category], "C", "D") else [Category]

 

This is new column script



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
New Member

Try this way : 

 

Step1 combine column " PO" and " Category" , 

Step2 replace"1006D" into "1006C" 

Step3 Split the combined column to " PO" and " Category"

Highlighted
Community Support
Community Support

HI @JoaoMS,

You can use replace value function with custom expression to add conditions to replace value steps:

    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Category],each if [PO]=1006 and [Category]="D" then "C" else [Category],Replacer.ReplaceText,{"Category"})

15.png

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Highlighted

Thank you, this is what I was looking for without creating a new column. I just made a small change "each if [PO]=1006 then "C" else [Category]", considering that there is just one PO named "1006" Regards

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors