Power Query Value.Add: Step-by-Step Guide
In this article
The Value.Add function in Power Query returns the sum of two values, handling numbers, durations, and other compatible types. To use it, you typically create a custom column or edit an existing formula, then call Value.Add(value1, value2) with the two values you want to add. This guide walks you through the process in Power Query Editor for Excel and Power BI, covering common scenarios and pitfalls.
What You'll Need
- Power Query Editor open in Excel (Data > Get & Transform Data > Launch Power Query Editor) or Power BI Desktop (Transform data).
- A query loaded with at least one table or data source.
- Basic familiarity with adding custom columns or editing M code.
Step-by-Step
- Open Power Query Editor. In Excel, go to the Data tab and click "Launch Power Query Editor" (or "Get Data" to import first). In Power BI Desktop, click "Transform data" on the Home ribbon. Menu labels may vary slightly by version or region.
- Load your data. If you haven't already, connect to your source (e.g., Excel workbook, CSV, database) and navigate to the table you want to work with. Ensure the columns you plan to add contain numeric values or compatible types.
- Add a custom column. Go to the "Add Column" tab and click "Custom Column". In the dialog, give your new column a name (e.g., "Total").
- Write the Value.Add formula. In the formula box, type
Value.Add(then select or type the first value or column reference (e.g.,[Price]), followed by a comma, then the second value (e.g.,[Tax]), and close the parenthesis. For example:Value.Add([Price], [Tax]). Note that column names are case-sensitive and must be enclosed in square brackets. - Check for errors and confirm. Click OK. Power Query will evaluate the expression for each row. If any row has a null or incompatible type, you may see an error. You can handle errors later.
- Adjust data types if needed. If the result column shows errors, ensure both input columns are numeric (or compatible). You can change data types by selecting the column and using the "Data Type" dropdown on the Home tab. For example, set both to Decimal Number or Int64.Type.
- Apply and close. Once satisfied, click "Close & Load" (Excel) or "Close & Apply" (Power BI) to load the results into your worksheet or data model.
Common Mistakes
- Using the + operator instead of Value.Add. While
[Price] + [Tax]works for numbers,Value.Addis more explicit and handles nulls differently (it returns null if either argument is null). Choose based on your needs. - Forgetting to handle nulls.
Value.Addreturns null if either argument is null. If you want to treat null as zero, wrap each argument withValue.Coalesceor use??operator:Value.Add([Price] ?? 0, [Tax] ?? 0). - Mismatched data types. Adding a number to a text column will cause an error. Ensure both arguments are of compatible types (e.g., both numbers, both durations).
- Incorrect column references. Column names with spaces or special characters must be enclosed in double quotes and square brackets, e.g.,
[#"Unit Price"]. - Not checking for errors after adding the column. Always preview the results; errors can propagate silently if you don't inspect the new column.
Tips
- Use
Value.Addwhen you need to add durations (e.g.,#duration(1,0,0,0)) or when you want consistent null propagation. - For simple numeric addition, the
+operator is shorter and equally valid. UseValue.Addwhen you need to be explicit about the operation or when working with non-numeric types. - Combine with
try ... otherwiseto handle errors gracefully:try Value.Add([A], [B]) otherwise null. - If you're adding many columns, consider using the "Standard" > "Add" button in the Add Column tab, which automatically generates a
Value.Addexpression for selected numeric columns. - Remember that Power Query is case-sensitive; ensure column names match exactly.
Troubleshooting
If Value.Add doesn't work as expected, try these steps in order:
- Check for errors in the new column. Click on the column header to see error messages. Common errors include "We cannot apply operator + to types Text and Number" or "Expression.Error: The name 'Value.Add' wasn't recognized." The latter usually means a typo or that you're using an older version of Power Query that doesn't support it (unlikely in modern versions).
- Verify data types. Select each input column and confirm the data type icon (e.g., 123 for whole number, 1.2 for decimal). Change if necessary using the Transform tab's Data Type dropdown.
- Handle nulls. If you see null results, decide whether to replace nulls with 0 using "Replace Values" (right-click column > Replace Values) or use
Value.Coalescein your formula. - Check for text that looks like numbers. Sometimes numbers are stored as text. Use "Change Type" > "Using Locale" to convert, or add a step to transform the column to number.
- Simplify the formula. Test with literal numbers:
Value.Add(1,2)to confirm the function works. Then replace with column references one at a time. - Update Power Query. If you're on an old version of Excel or Power BI, some functions may not be available. Update to the latest version via your Microsoft 365 or Power BI updates.
Frequently Asked Questions
What types can Value.Add handle?
Value.Add works with numbers (Int32, Int64, Decimal, etc.), durations, and dates (adding a duration to a date). It does not work with text or logical values.
How is Value.Add different from the + operator?
Both perform addition, but Value.Add is a function that explicitly returns null if either argument is null, while the + operator also returns null for null inputs. The main difference is syntax and that Value.Add can be used with non-numeric types like durations.
Can I add more than two values at once?
No, Value.Add takes exactly two arguments. To add three values, nest calls: Value.Add(Value.Add(a,b),c).
Why does my Value.Add formula return an error?
Common causes: mismatched data types (e.g., text + number), incorrect column names (case-sensitive), or null values that aren't handled. Check the error message for clues.
Is Value.Add available in all Power Query versions?
Yes, it's a standard function in Power Query for Excel and Power BI. If you get a "not recognized" error, ensure you're using the latest version.
Can I use Value.Add in a calculated column in Power Pivot?
No, Value.Add is specific to Power Query (M language). In DAX (Power Pivot), use the + operator or SUM function.