Power Query Table.ReplaceValue Function Guide
In this article
The Table.ReplaceValue function in Power Query is used to find a specific value within a table or a specific column and replace it with a different value. To use it, you need a table as your source, the value to be replaced, the replacement value, and a replacement method (usually Replacer.ReplaceText for strings or Replacer.ReplaceValue for general data types).
What You'll Need
- Microsoft Excel or Power BI Desktop with Power Query installed.
- A dataset loaded into the Power Query Editor.
- Basic familiarity with the Power Query formula bar (View > Formula Bar).
- A clear understanding of whether you are replacing exact matches or partial text strings.
Step-by-Step
- Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
- Select Your Column: Click on the header of the column containing the values you wish to change. If you intend to replace values across the entire table, you can skip the selection, though the UI typically requires a column selection to generate the initial code.
- Use the UI Shortcut: Right-click the column header and select Replace Values... from the context menu. This opens a dialog box.
- Define the Values: In the "Value To Find" box, type the exact value you want to remove. In the "Replace With" box, type the new value. Click OK.
- Analyze the Generated Code: Look at the formula bar. You will see a step that looks like this:
= Table.ReplaceValue(#"Previous Step", "Old Value", "New Value", Replacer.ReplaceText, {"ColumnName"}). - Modify for Case Sensitivity: By default,
Replacer.ReplaceTextis case-sensitive. If you need to ignore case, you must modify the M code. Replace theReplacer.ReplaceTextpart with a custom function or ensure your data is normalized to lowercase/uppercase using Transform > lowercase before performing the replacement. - Expand to Multiple Columns: If you want the same replacement to happen across five different columns, you do not need five separate steps. In the formula bar, locate the list at the end of the function:
{"ColumnName"}. Change this to a list of all target columns:{"Column1", "Column2", "Column3"}. - Implement Dynamic Replacements: If the replacement value needs to come from another cell or a parameter, replace the hard-coded "New Value" string in the formula bar with the name of your Power Query parameter or a reference to another step.
- Apply and Close: Once the values are replaced correctly in the preview, click File > Close & Apply to load the cleaned data into your spreadsheet or model.
Common Mistakes
One of the most frequent errors is confusing Replacer.ReplaceText with Replacer.ReplaceValue. Replacer.ReplaceText is designed specifically for text strings and allows for partial matches (e.g., replacing "Street" with "St." within a full address). Replacer.ReplaceValue is used for exact matches of the entire cell content, regardless of whether the data is a number, date, or text. If you use Replacer.ReplaceValue to try and change a word inside a sentence, nothing will happen because the function is looking for a cell that contains only that word.
Another common mistake is ignoring data types. If you are trying to replace the number 10 with the number 20, but the column is formatted as Text, the function will fail unless you wrap the numbers in quotation marks ("10", "20"). Conversely, if the column is a Number type and you provide "10" (as text), Power Query may return an error or simply fail to find the match.
Users often forget that Power Query is case-sensitive. Searching for "apple" will not find "Apple" or "APPLE". This leads to "ghost data" where some rows are updated and others are not, creating inconsistencies in reports. To avoid this, it is best practice to use the Transform > Format > Capitalize Each Word or Lowercase tool on the column before applying the replacement.
Tips
To handle complex replacements that Table.ReplaceValue cannot manage—such as replacing values based on a conditional logic (e.g., if Column A is X, replace Column B with Y)—do not use this function. Instead, use a Conditional Column (Add Column > Conditional Column). This allows you to keep the original data while creating a cleaned version in a new column, which is safer for auditing.
When dealing with null values, the standard "Replace Values" dialog can sometimes be tricky. To replace nulls, leave the "Value To Find" box completely empty or explicitly type null (without quotes) in the M code formula bar. This is essential for cleaning datasets where missing data is represented by nulls rather than empty strings.
For those managing very large datasets, minimize the number of Table.ReplaceValue steps. Each step creates a new version of the table in memory. If you have ten different replacements to make in one column, it is more efficient to write a custom function or use a mapping table and a Merge join rather than stacking ten separate Replace Value steps.
Troubleshooting
If the values are not being replaced despite the text appearing identical, first check for leading or trailing spaces. A cell containing "New York " (with a space at the end) will not be caught by a search for "New York". To fix this, right-click the column and select Transform > Trim before applying the replacement.
If you receive a "Type Mismatch" error, check the data type icon to the left of the column header. If it shows "123" (Whole Number) but your replacement formula uses quotes (e.g., "10"), the function will error out. Change the data type to Text or remove the quotes from the formula bar to match the numeric type.
If the replacement is happening in the wrong columns, check the list at the end of the M code. Ensure the column names are spelled exactly as they appear in the previous step, including capitalization. If you renamed a column in a previous step, the Table.ReplaceValue function must use the new name, not the original source name.
If the formula bar is missing, you cannot manually edit the Replacer method. Go to the View tab in the ribbon and check the box for "Formula Bar". This is the only way to switch between ReplaceText and ReplaceValue manually.
Frequently Asked Questions
Can I replace values across multiple columns at once?
Yes. While the user interface only lets you select one column at a time, you can edit the M code in the formula bar. Change the final argument from a single-item list {"Column1"} to a multi-item list {"Column1", "Column2", "Column3"}.
What is the difference between ReplaceText and ReplaceValue?
Replacer.ReplaceText looks for a substring within a text cell and replaces it, making it ideal for partial matches. Replacer.ReplaceValue looks for the exact content of the entire cell and replaces it, which is necessary for numbers, dates, or exact-match text.
How do I replace a value with a blank cell?
To replace a value with a truly empty cell (null), you must edit the formula bar. Replace the "New Value" string with the keyword null without any quotation marks. Using empty quotes "" will create an empty string, which is technically different from a null value.
Is Table.ReplaceValue case-sensitive?
Yes, it is strictly case-sensitive. "Data" and "data" are treated as different values. To perform a case-insensitive replacement, you should first transform the column to lowercase or uppercase using the Transform menu.
Can I use a list from another table to replace values?
Table.ReplaceValue is not designed for list-based replacements. For that, the best approach is to create a "Mapping Table" with two columns (Old Value and New Value) and use the Merge Queries feature to join the mapping table to your main data, then expand the New Value column.