How to Use AVERAGEX in DAX in Power BI: Syntax and Examples
Use
AVERAGEX in DAX to calculate the average of an expression evaluated over a table. It takes two arguments: a table and an expression to evaluate for each row, then returns the average of those results.Syntax
The AVERAGEX function requires two parts:
- Table: The set of rows to evaluate.
- Expression: The calculation done on each row.
It returns the average of the expression results across the table.
DAX
AVERAGEX(<Table>, <Expression>)
Example
This example calculates the average sales amount per product from a table named Sales with columns Product and SalesAmount.
DAX
Average Sales = AVERAGEX(Sales, Sales[SalesAmount])
Output
If Sales table has SalesAmount values: 100, 200, 300, the result is 200
Common Pitfalls
Common mistakes include:
- Using
AVERAGEXwithout a proper table argument, which causes errors. - Confusing
AVERAGEXwithAVERAGE, which only works on a single column. - Writing expressions that return non-numeric values, causing calculation errors.
Always ensure the expression returns numbers and the table is correctly filtered if needed.
DAX
/* Wrong: Using a column instead of a table */ Average Wrong = AVERAGEX(Sales[SalesAmount], Sales[SalesAmount]) /* Correct: Use the whole table */ Average Correct = AVERAGEX(Sales, Sales[SalesAmount])
Quick Reference
| Argument | Description |
|---|---|
Table | The table to iterate over. |
Expression | The calculation to perform on each row. |
| Return | Average of the expression results as a number. |
Key Takeaways
AVERAGEX calculates the average of an expression evaluated row by row over a table.
Always provide a table as the first argument and a numeric expression as the second.
Do not confuse AVERAGEX with AVERAGE; AVERAGE works on a single column only.
Ensure your expression returns numbers to avoid errors.
Use AVERAGEX to perform averages on calculated or filtered data, not just raw columns.