Multiple Table.ReplaceValue

CountryBoy_71

New Member
Joined
Nov 24, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Good afternoon all,

Wondering if someone can help explain why this isn't working? The first example is based on another post here, the second is what I am attempting. For me, the "[ ]" resulted in a syntax error, while wrapping in the "{ }" provided valid code but doesn't actually do anything.

Power Query:
= Table.ReplaceValue(#"Changed Type",each [Service Number], each if [Service Number] = " " then "" else if [Service Number] = "-" then "" else [Service Number],Replacer.ReplaceText,{"Service Number"})

Power Query:
= Table.ReplaceValue(#"Changed Type",each {"Service Number"}, each if {"Service Number"} = " " then "" else if {"Service Number"} = "-" then "" else {"Service Number"},Replacer.ReplaceText,{"Service Number"})

The column is a 'text' type and then converted to a 'int' in the next step.

I also realize that trying to make one step out of two may be a bit of a waste, but I also have another set of 4, replacing values that I am trying to clean up.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
try

Power Query:
= Table.TransformColumns(#"Changed Type",{"Service Number", each if List.Contains({" ", "-"},_) then null else _})
 
Upvote 0
try

Power Query:
= Table.TransformColumns(#"Changed Type",{"Service Number", each if List.Contains({" ", "-"},_) then null else _})
This would never cross my mind. Cool tip!
I always went with something like below.
Power Query:
= Table.ReplaceValue(#"Changed Type",each [Service Number], each if List.AnyTrue({[Service Number] = " " , [Service Number] = "-"}) then "" else [Service Number],Replacer.ReplaceText,{"Service Number"})
 
Upvote 0
The first syntax is correct assuming those are the correct step and column names. What was the actual error message?
The 'error' was actually just a result of my fat finger...got that resolved, now, all the of the above solutions return valid syntax for me except that none of them actually return results. I am still left with the same column of data. The subsequent step changed type to 'int' and that was error'ing out because the replace step didn't actually replace anything.

I feel like some days excel and I aren't very good friends.
 
Upvote 0
If it's not replacing anything, then it must be that none of the service number data actually matches your tests.
 
Upvote 0
So if the service number needs to be a number, then you can changes the type, then from the UI replace error. It's in the same place Here you found replace values.
 
Upvote 0
Here one more

Power Query:
=List.Accumulate({" ","-"}, #"Changed Type", (s,c) => Table.ReplaceValue(s,c,null,Replacer.ReplaceValue,{"Service Number"}))
 
Upvote 0
Solution
Here one more

Power Query:
=List.Accumulate({" ","-"}, #"Changed Type", (s,c) => Table.ReplaceValue(s,c,null,Replacer.ReplaceValue,{"Service Number"}))
Thanks @JEC This is essentially the one that I went with. Only difference is that I created a separate referencing list. Overkill for two items but practice!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top