0
0
Power-biHow-ToBeginner ยท 3 min read

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 AVERAGEX without a proper table argument, which causes errors.
  • Confusing AVERAGEX with AVERAGE, 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

ArgumentDescription
TableThe table to iterate over.
ExpressionThe calculation to perform on each row.
ReturnAverage 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.