The List.ReplaceValue function in Power Query finds a value in a list and replaces every occurrence of it with a new value. You can replace whole values, like a code or a placeholder number, or just part of the text inside each item.
Since any column of a table can be turned into a list, it’s also a quick way to clean up the values in a column before you use them in another step.
Follow along with the example file
List.ReplaceValue Function Examples.xlsx
List.ReplaceValue Function Syntax
List.ReplaceValue(list as list, oldValue as any, newValue as any, replacer as function) as list
- list – the list you want to search. It can be a list you type in curly brackets, such as
{"HR","Fin","IT"}, or a column of a table. - oldValue – the value you want to find. It can be text, a number, a date, or null.
- newValue – the value that replaces each match.
- replacer – a function that decides what counts as a match and how the replacement is made. Use
Replacer.ReplaceValueto replace items that are exactly equal to oldValue, orReplacer.ReplaceTextto replace oldValue wherever it shows up inside the text. You can also write your own function here (Examples 7 and 9).
The replacer isn’t optional. If you leave it out, Power Query gives you an error, so always give List.ReplaceValue all four arguments.
What it returns: A new list with the replacements made. Items that don’t match stay as they are, and if nothing matches at all, you get the same list back with no error.
The List.ReplaceValue function is part of the Power Query M language, so it works wherever Power Query does in Excel: Excel 365, 2024, 2021, 2019, and 2016 for Windows, and Excel for Microsoft 365 on Mac.
When to Use the List.ReplaceValue Function
Use this function when you need to:
- Replace a code or abbreviation with its full name
- Turn a placeholder value like -999 into null
- Replace blank cells (null) in a column with 0
- Change or remove a character inside every item, such as the dots in phone numbers
- Replace a value no matter how it was typed in upper or lower case
- Replace several values at once using a lookup table
- Cap every number above a limit
Example 1: Replace One Value in a List
Let’s start with the simplest use. Suppose you have a list of department codes where the finance team shows up as “Fin”, and you want the full name “Finance” instead.
In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor that opens, type this formula in the formula bar:
= List.ReplaceValue({"HR","Fin","IT","Fin","Ops"},"Fin","Finance",Replacer.ReplaceValue)
Result: A list with HR, Finance, IT, Finance, and Ops

Here, List.ReplaceValue looks at each of the five codes and replaces both “Fin” items with “Finance”. The other codes don’t match, so they stay as they are.
Replacer.ReplaceValue only replaces an item when the whole item is equal to “Fin”. So a code like “FinOps” would not change, because it isn’t exactly “Fin”.
The match is also case-sensitive, so “fin” or “FIN” would not be replaced either. Example 7 shows how to get around that.
In the example file, Example 1 types its values right into the query, so it doesn’t have a sheet. You can open it from Data > Queries & Connections.
Example 2: Replace a Placeholder Number with null
This one is common with data that comes out of other systems. Suppose a temperature sensor writes -999 whenever it fails to take a reading, and you want those readings to be empty (null) instead.
Create a new blank query (as in Example 1) and use this formula:
= List.ReplaceValue({21.4,22.1,-999,22.9,-999,22.8},-999,null,Replacer.ReplaceValue)
Result: A list with 21.4, 22.1, null, 22.9, null, and 22.8

Here, oldValue is the number -999 and newValue is null, so both failed readings become null. Replacer.ReplaceValue works with numbers, dates, and null, not just text.
You see the difference when you calculate with the list. The average of the original list is about -318.13 because of the two -999 values, but the List.Average function skips null, so the cleaned list gives you 22.3.
Example 3: Replace Blank Cells (null) with 0 in a Column
Now let’s go the other way and fill in the blanks. Below is a table named WeeklyUnits with the units each sales rep sold this week, and I want the Units Sold values as a list with 0 in place of the blank cells.
The two reps with a blank cell didn’t sell anything this week, so 0 is the right number for them.

In the code below, the Source line uses the Excel.CurrentWorkbook function to pull the WeeklyUnits table into Power Query by its name.
If you try this on your own data, format it as a table (Ctrl + T) and put your table’s name in place of “WeeklyUnits”.
Create a new blank query, open the Advanced Editor (Home > Advanced Editor), and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="WeeklyUnits"]}[Content],
Units = List.ReplaceValue(Source[Units Sold],null,0,Replacer.ReplaceValue)
in
Units
Result: A list with 42, 0, 37, 0, 51, and 28

Here, Source is the name of the first step, and it holds the WeeklyUnits table. Source[Units Sold] takes the Units Sold column as a list.
A blank cell comes into Power Query as null, so oldValue is null, and List.ReplaceValue replaces each null with 0.
The result is a list, not a table. If you want to replace the values right inside the table’s column and keep the other columns, use the Table.ReplaceValue function on the table instead.
Example 4: Replace Part of the Text in Each Item
So far, each match was a whole item. Below is a table named VendorPhones where some phone numbers use dots and others use dashes, and I want all of them in the same 555-201-3344 style.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="VendorPhones"]}[Content],
Phones = List.ReplaceValue(Source[Phone],".","-",Replacer.ReplaceText)
in
Phones
Result: A list with 555-201-3344, 555-318-9020, 555-476-1185, 555-633-2701, and 555-742-5568

Here, the replacer is Replacer.ReplaceText, so List.ReplaceValue looks for the dot inside each phone number, not for an item that is only a dot. It replaces every dot it finds, so both dots in 555.201.3344 become dashes.
The numbers that already had dashes have no dots to replace, so they stay the same.
Replacer.ReplaceText only changes text. So if someone typed a phone number as plain digits (which comes in as a number) or left a cell blank (null), List.ReplaceValue leaves that item as it is, and you don’t get an error.
If you only need to change one piece of text, not a whole list, the Text.Replace function does the same job on a single text value.
Follow along with the example file
List.ReplaceValue Function Examples.xlsx
Example 5: Remove a Character from Each Item
This next one is a handy trick. Below is a table named OnlineOrders where every order number starts with a # sign, and I want the order numbers without the #.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="OnlineOrders"]}[Content],
OrderNumbers = List.ReplaceValue(Source[Order No],"#","",Replacer.ReplaceText)
in
OrderNumbers
Result: A list with 5101, 5102, 5103, 5104, and 5105

Here, newValue is "", which is empty text. Replacing the # sign with nothing removes it, so “#5101” becomes “5101”.
Note that the order numbers are still text, even though they look like numbers now. If you need real numbers, convert each item in the list with the Number.From function, using the List.Transform function.
Example 6: Replacer.ReplaceValue vs Replacer.ReplaceText
This example shows why the replacer you pick makes a big difference. Suppose you have a list of street names where “St” is short for Street, and you want to replace “St” with “Street”.
This example uses both replacers on the same list and puts the results side by side. Create a new blank query, open the Advanced Editor, and use this code:
let
Streets = {"St","Main St","Stone Ave","St."},
WholeValue = List.ReplaceValue(Streets,"St","Street",Replacer.ReplaceValue),
PartText = List.ReplaceValue(Streets,"St","Street",Replacer.ReplaceText),
Comparison = Table.FromColumns({Streets,WholeValue,PartText},{"Original","Replacer.ReplaceValue","Replacer.ReplaceText"})
in
Comparison
Result: A table where the Replacer.ReplaceValue column has “Street”, “Main St”, “Stone Ave”, and “St.”, and the Replacer.ReplaceText column has “Street”, “Main Street”, “Streetone Ave”, and “Street.”

Here, the WholeValue step uses Replacer.ReplaceValue, so only the item that is exactly “St” changes. “Main St” and “St.” are left alone, because neither one is exactly “St”.
The PartText step uses Replacer.ReplaceText, so it replaces “St” wherever it shows up in the text. That fixes “Main St” and “St.”, but it also turns “Stone Ave” into “Streetone Ave”, because “Stone” starts with “St”.
The last step, Comparison, uses the Table.FromColumns function just to show the three lists next to each other.
So use Replacer.ReplaceValue when you’re replacing whole values, and Replacer.ReplaceText only when the text you’re replacing can’t show up inside other words.
Example 7: Replace a Value While Ignoring Upper and Lower Case
As you saw in Example 1, the match is case-sensitive. Below is a table named SurveyAnswers where people typed “yes” in three different ways, and I want every yes as “Yes”.

If you use Replacer.ReplaceValue here, only the two lowercase “yes” answers change, and “YES” stays in capital letters. So write your own replacer function that ignores case.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="SurveyAnswers"]}[Content],
Answers = List.ReplaceValue(Source[Answer],"yes","Yes",(value,old,new)=>if Text.Lower(value)=Text.Lower(old) then new else value)
in
Answers
Result: A list with Yes, Yes, Yes, No, No, and Yes

Here, the last argument is a custom replacer. List.ReplaceValue runs it once for every answer and passes it three things: the answer (value), the oldValue “yes” (old), and the newValue “Yes” (new).
The function turns both the answer and “yes” into lowercase with the Text.Lower function and compares them. If they match, it returns “Yes”, and if not, it returns the answer unchanged, so the No answers stay as they are.
Example 8: Replace Several Values Using a Lookup Table
List.ReplaceValue replaces one value at a time. Below is a table named Shipments with the country code of each shipment, and I want the full country names in place of the codes.

The codes and their full names are in a second table named CountryCodes, on the Example 8 Codes sheet.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="Shipments"]}[Content],
Codes = Table.ToRows(Excel.CurrentWorkbook(){[Name="CountryCodes"]}[Content]),
Countries = List.Accumulate(Codes,Source[Country],(state,pair)=>List.ReplaceValue(state,pair{0},pair{1},Replacer.ReplaceValue))
in
Countries
Result: A list with United States, United Kingdom, Canada, United States, DE, and United Kingdom

Here, the Codes step uses the Table.ToRows function to turn the CountryCodes table into a list of pairs, like {“US”,”United States”}.
The List.Accumulate function then goes through the pairs one by one. In each pair, pair{0} is the first item (the code) and pair{1} is the second item (the full name).
List.Accumulate starts with the Country column as a list, called state, and runs List.ReplaceValue on it for the first pair. The list it gets back becomes the new state for the next pair, so the replacements build up until all three codes are done.
DE isn’t in the CountryCodes table, so it stays as DE. To handle more codes later, just add rows to the CountryCodes table and refresh the query.
Since the pairs follow the column order of CountryCodes, keep the codes in its first column.
This runs one replacement for every row of the lookup table, so when the lookup table has thousands of rows, merging the two tables is usually the better choice.
Example 9: Cap Every Number Above a Limit
A custom replacer can do more than check for a match. Below is a table named Discounts with the discount on each product, and since the store’s rule is that no discount can go above 30%, I want every discount above 30 replaced with 30.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="Discounts"]}[Content],
Capped = List.ReplaceValue(Source[#"Discount (%)"],30,30,(value,old,new)=>if value>old then new else value)
in
Capped
Result: A list with 15, 30, 25, 30, and 10

Here, oldValue is the limit (30) and newValue is what to put in its place (also 30). The custom replacer checks each discount and returns 30 when the discount is greater than 30, or the discount unchanged when it isn’t.
So 40 and 35 become 30, and 15, 25, and 10 stay as they are. The column name has parentheses and a % sign in it, so it’s written as Source[#"Discount (%)"], unlike Source[Units Sold] in Example 3.
You can get the same result with the List.Transform function, like List.Transform(Source[#"Discount (%)"],each List.Min({_,30})). This example is mainly here to show that a custom replacer can check any condition you want.
Other Excel Articles You May Also Like:
- List.RemoveItems function
- List.RemoveNulls
- Table.Schema Function in Power Query M
- Text.Remove – Use Text.Remove in Power Query M to strip characters from text.
- List.Difference – Use List.Difference in Power Query M to find items in one list but not another.
- List.Contains – Use List.Contains in Power Query M to check if a value exists in a list.
- Text.Lower – Use Text.Lower in Power Query M to convert text to lowercase.
- List.Distinct – Use List.Distinct in Power Query M to remove duplicates from a list.