Power Query List.ReplaceValue Function: Step-by-Step Guide
In this article
The List.ReplaceValue function in Power Query replaces all occurrences of a specified value with another value within a list. It works only on lists—not tables columns directly—and requires the list to be in memory (e.g., created via List.Generate, { } syntax, or extracted from a column using Table.Column). No special setup is needed beyond having data loaded into Power Query.
What You'll Need
- A working Power Query environment (in Excel or Power BI)
- A list of values (e.g., a column converted to a list, or a manually defined list)
- The exact original value to replace (case-sensitive unless you use List.Transform with Text.Lower/Upper)
- The replacement value (same data type recommended)
Step-by-Step
- Open Power Query Editor: In Excel, go to the Data tab > Get Data > From Other Sources > Blank Query, or open an existing query. In Power BI, go to Home > Transform Data.
- Create or identify your list. For example, if you have a table with a column named "Status", right-click the table name in the Queries pane, choose Reference, then in the new query, click the column header and select Transform > Column > Using Custom Column. In the formula bar, type = {List.Distinct(#"Previous Step"[Status])} to extract the list of unique values. Alternatively, type = {"Pending", "Approved", "Pending", "Rejected"} directly into the formula bar to create a static list.
- Click the fx icon next to the formula bar to open the function builder, or type the function manually. The syntax is: List.ReplaceValue(list, oldText, newText, optional replacementMode).
- Enter the list reference. If your list is named "MyList", type MyList. If it’s inline, use the full list literal: {"Pending", "Approved", "Pending", "Rejected"}.
- Specify the value to find. Use quotes around text: "Pending". For numbers, omit quotes: 0 or 1.25. Ensure the data type matches exactly—"0" (text) ≠ 0 (number).
- Enter the replacement value: "Approved" or 1, depending on your goal. Again, match the data type to avoid unexpected errors.
- Optionally specify the replacement mode. Use List.ReplaceAll (default, replaces all occurrences) or List.ReplaceOne (replaces only the first match). To control this, add the fourth argument: , Replacer.ReplaceAll or , Replacer.ReplaceOne. Example: List.ReplaceValue(MyList, "Pending", "Approved", Replacer.ReplaceAll).
- Press Enter to apply. The result appears instantly in the preview pane. Click Close & Load to push the transformed list back to Excel or Power BI as a table (Power Query will convert the list to a single-column table).
Common Mistakes
- Using List.ReplaceValue on a table column directly instead of extracting the list first. List.ReplaceValue only accepts a list as its first argument.
- Mismatched data types: searching for "0" (text) in a list of numbers will return the original list unchanged.
- Case sensitivity: List.ReplaceValue is case-sensitive. "pending" ≠ "Pending". Use List.Transform with Text.Lower to normalize before replacing if needed.
- Forgetting to quote text values: List.ReplaceValue(MyList, Pending, "Approved") (without quotes) will cause an error because "Pending" is interpreted as a variable.
- Assuming it edits in-place: Power Query is functional and immutable. List.ReplaceValue returns a *new* list; it does not modify the original list unless you assign it to a new step.
Tips
- Test with a small list first: = List.ReplaceValue({"A", "B", "A"}, "A", "C") confirms behavior before applying to large datasets.
- Combine with Table.AddColumn for column replacements: = Table.ReplaceValue(#"Previous Step", each [Status], each if [Status] = "Pending" then "Approved" else [Status], Replacer.ReplaceValue, {"Status"}). List.ReplaceValue alone cannot replace column values in a table directly.
- Use List.Transform for conditional replacements: = List.Transform(MyList, each if _ = "Pending" then "Approved" else _). This gives more control for complex logic.
- Check for nulls: List.ReplaceValue will replace null if you explicitly pass null as the old value. Example: List.ReplaceValue(MyList, null, "Unknown").
- Use List.Distinct after replacing if you need unique values: = List.Distinct(List.ReplaceValue(MyList, "Pending", "Approved")) avoids duplicates in reporting.
Troubleshooting
If List.ReplaceValue doesn’t change your data, follow these checks:
- Verify the list contains the value: Add a step with = List.Contains(MyList, "Pending") to confirm "Pending" exists (returns true/false).
- Check data types: Use = List.Transform(MyList, type) to inspect each item’s type. If some are text and others numbers, List.ReplaceValue will fail to match.
- Inspect for invisible characters: Leading/trailing spaces or non-breaking spaces (e.g., "Pending ") won’t match "Pending". Use = List.Transform(MyList, Text.Trim) before replacing.
- Ensure you’re using the correct function: List.ReplaceValue is for lists. For tables, use Table.ReplaceValue instead.
- Review error messages: If you see "Expression.Error: The name 'MyList' wasn't recognized", check the step name in the Applied Steps pane—rename steps or use full paths like #"Step Name".
- Restart Power Query: Sometimes the editor glitches. Close and reopen Excel/Power BI, then reload the query.
Frequently Asked Questions
Can List.ReplaceValue replace multiple different values at once?
No. List.ReplaceValue replaces one old value with one new value per call. To replace multiple values, chain calls (e.g., List.ReplaceValue(List.ReplaceValue(list, "A", "X"), "B", "Y")) or use List.Transform with a conditional.
Does List.ReplaceValue work with dates?
Yes, but only if the list contains actual date values (not text). For example, if your list is {#date(2024,1,1), #date(2024,1,2)}, you can replace #date(2024,1,1) with #date(2024,1,3). Replacing text like "2024-01-01" in a date list won’t work.
How do I replace values case-insensitively?
Convert both the list and target to lowercase first: = List.ReplaceValue(List.Transform(MyList, Text.Lower), "pending", "approved", Replacer.ReplaceAll). Then use List.Transform again to restore original casing if needed.
What happens if I pass null as the old value?
It replaces null entries in the list with the new value. For example, List.ReplaceValue({"A", null, "B"}, null, "Missing") returns {"A", "Missing", "B"}.
Can I use List.ReplaceValue inside a function that processes multiple tables?
Yes, but only after extracting the list from each table (e.g., using Table.Column(table, "ColumnName")). Then apply List.ReplaceValue to that extracted list.
Why does my list turn into a table when I load it?
Power Query always exports lists as single-column tables in Excel/Power BI. This is normal behavior and doesn’t affect the data integrity—you’ll just see a column named "Column1".