Power Query has no built-in COALESCE function, but you can achieve the same result with a custom column formula that returns the first non-null value from a list. The shortest working approach is to add a custom column with List.First(List.RemoveNulls({[Column1], [Column2], [Column3]})), replacing the column names with your own. This returns the first value that is not null, exactly like SQL COALESCE. The steps below walk through the process in the Power Query Editor, which is available in Excel, Power BI Desktop, and other Microsoft tools that host Power Query.
What You'll Need
- Excel (Microsoft 365 or Excel 2019 and later) or Power BI Desktop with the Power Query Editor available. In Excel, the editor opens from the Data tab under Get & Transform Data. In Power BI Desktop, it opens from the Home tab under Transform Data. Menu labels can differ slightly by version and region.
- A table loaded into Power Query with at least two columns that may contain null values.
- Basic familiarity with adding a custom column and writing a short M formula.
Step-by-Step
- Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform Data to open the Power Query Editor with your query selected. If your data is already loaded, open the editor and select the query in the Queries pane on the left.
- Confirm the column names. Look at the column headers in the preview. You will need the exact names, including spaces and punctuation, for the formula. If a header contains spaces, wrap the name in square brackets and double quotes, for example
[\"First Name\"]. If you are unsure, you can rename columns to simple names like Column1, Column2 before writing the formula. - Add a custom column. On the Add Column tab, click Custom Column. The Custom Column dialog opens with a name field and a formula box.
- Name the new column. Type a name such as Coalesced or FirstAvailable in the New column name field.
- Enter the coalesce formula. In the formula box, type
List.First(List.RemoveNulls({[Column1], [Column2], [Column3]})). Replace Column1, Column2, and Column3 with your actual column names. You can list as many columns as you need inside the curly braces, separated by commas. The order matters: the first non-null value in that list is returned. - Check the formula for syntax errors. Column names go inside square brackets. The list of columns goes inside curly braces. The function names are case-sensitive in M:
List.FirstandList.RemoveNullsmust be written exactly. If the dialog shows a syntax error, compare your formula against the example character by character. - Click OK. Power Query adds the new column to the preview. Scroll right to see it. Each row should show the first non-null value from the listed columns.
- Verify the results. Scan a few rows where the first column is null and the second has a value. The new column should show the second column's value. Where all listed columns are null, the formula returns null. That is expected behavior, matching SQL COALESCE.
- Handle the all-null case if needed. If you want a default value instead of null when every column is empty, wrap the formula:
List.First(List.RemoveNulls({[Column1], [Column2], [Column3]}), \"Unknown\"). The second argument toList.Firstis the default returned when the list is empty. - Apply and load. Click Close & Load in Excel or Close & Apply in Power BI Desktop to load the query with the new column into your worksheet or data model.
Common Mistakes
- Forgetting the curly braces. The columns must be wrapped in
{ }to form a list. WritingList.RemoveNulls([Column1], [Column2])will fail because the function expects a single list argument. - Using the wrong column names. If a column name has a space and you write
[First Name]without quotes, the formula errors. Use[\"First Name\"]instead. - Assuming empty text is null.
List.RemoveNullsremoves nulls only. An empty string\"\"is not null and will be returned as the first value. If your data uses empty strings for missing values, replace them first with Transform > Replace Values, or use a formula that also filters blanks. - Mixing up column order. COALESCE returns the first non-null in the order you list the columns. If you list them in the wrong order, you get a different result.
- Expecting a built-in COALESCE function. Power Query's formula language (M) does not have a function named COALESCE. The list-based approach above is the standard workaround.
Tips
- For many columns, build the list in a text editor first and paste it into the formula box to avoid typos.
- If you need to coalesce values from columns with different data types, convert them to a common type first using the Transform tab, or the formula may return an error.
- You can use the same pattern inside a
Table.AddColumnstep in the Advanced Editor if you prefer writing M directly. The logic is identical. - To treat empty strings as missing, add a step that replaces
\"\"with null before the custom column, then the coalesce formula works as expected. - Name the new column clearly so downstream steps and reports are easy to read.
Troubleshooting
- The formula box shows a syntax error. Check parentheses, braces, and brackets. The structure is
List.First(List.RemoveNulls({...})): two opening parentheses, one opening brace, then columns, then one closing brace, two closing parentheses. Also confirm function names are capitalized exactly as shown. - The new column shows errors instead of values. This usually means a column name does not match. Open the Advanced Editor (Home > Advanced Editor) to see the step and compare names. Alternatively, a data type mismatch can cause errors; check the column types in the preview header.
- Empty strings appear instead of the next column's value. As noted,
List.RemoveNullsdoes not remove empty text. Add a Replace Values step to turn empty strings into null before the custom column. - The column is missing after loading. Make sure you clicked Close & Load (Excel) or Close & Apply (Power BI) and that the query was not left in the editor without applying changes.
- Results changed after a refresh. If source columns are added or renamed, the formula may break. Update the column names in the custom column step.
Frequently Asked Questions
Is there a COALESCE function in Power Query?
No. M, the language behind Power Query, has no function named COALESCE. The standard approach is List.First(List.RemoveNulls({...})), which returns the first non-null value from a list of columns.
Can I coalesce more than three columns?
Yes. Add as many column names as you need inside the curly braces, separated by commas. The order determines which value is returned first.
What happens if all columns are null?
The formula returns null. To return a default instead, pass a second argument to List.First, such as List.First(List.RemoveNulls({...}), \"Unknown\").
Does this work in both Excel and Power BI?
Yes. The Power Query Editor and the M language are the same in both, so the formula works identically. Menu labels may differ slightly between versions.
How do I treat empty text as missing?
Replace empty strings with null before adding the custom column. Use Transform > Replace Values to replace \"\" with null, then apply the coalesce formula.
Can I use this in the Advanced Editor?
Yes. The same expression can be placed inside a Table.AddColumn step. The custom column dialog simply generates that step for you.