DAX AVERAGEX Function
Get last date in the current context in DAX.
AVERAGEX
is an iterator function in DAX that:
- Iterates over a table
- Evaluates an expression for each row
- Returns the average of all evaluated values
It’s similar to SUMX
, but instead of summing, it averages the result of the expression.
Syntax
AVERAGEX(<table>, <expression>)
<table>
: A real or virtual table to iterate over<expression>
: An expression evaluated row-by-row
Example
Suppose you have a table Sales
:
Product | Quantity | UnitPrice |
---|---|---|
A | 2 | 10 |
B | 3 | 15 |
C | 1 | 20 |
You want the average revenue per transaction (Quantity * UnitPrice
for each row).
DAX formula
AVERAGEX(Sales, Sales[Quantity] * Sales[UnitPrice])
- Step-by-step:
Row | Calculation | Result |
---|---|---|
1 | 2 × 10 | 20 |
2 | 3 × 15 | 45 |
3 | 1 × 20 | 20 |
Average = (20 + 45 + 20) / 3 = 28.33
AVERAGE
?
Why Not Use The regular AVERAGE
function only works on a single column — you can't use it to compute Quantity * UnitPrice
.
AVERAGE(Sales[Quantity] * Sales[UnitPrice])
-- This will throw an error
You need AVERAGEX
for expressions.
AVERAGEX
Real-world Use Cases for Scenario | Example Expression |
---|---|
Average revenue per transaction | Sales[Quantity] * Sales[UnitPrice] |
Average discount given | Orders[DiscountAmount] / Orders[Total] |
Average price of products in a filtered category | With FILTER(Products, ...) , then Price |
Average custom metric based on calculated columns/measures | Any row-based expression |
Works with Virtual Tables
You can use AVERAGEX
with DAX functions like FILTER
, VALUES
, or SUMMARIZE
to create dynamic row sets:
AVERAGEX(
FILTER(Sales, Sales[Quantity] > 1),
Sales[Quantity] * Sales[UnitPrice]
)
This averages revenue only for rows with quantity > 1.
Summary
Feature | Description |
---|---|
Function type | Iterator |
Iterates over | A table (real or virtual) |
Evaluates | An expression row-by-row |
Returns | Average of the evaluated values |
Use case | Row-level average, especially with expressions |
Compared to AVERAGE | AVERAGE = simple column average, no expression support |
No questions available.