AVERAGEX DAX Function in Power BI

The AVERAGEX function in Data Analysis Expressions (DAX) is a powerful iterator designed to calculate the arithmetic mean of an expression evaluated for each row of a table. Unlike the standard AVERAGE function, which performs a simple column-level aggregation, AVERAGEX allows you to perform complex row-level calculations (such as multiplying price by quantity or applying tax rates) before the final average is computed. This makes it an indispensable tool for scenarios involving weighted averages, dynamic filtering, and multi-category performance analysis where a simple column average would be mathematically incorrect.

DAX Syntax AVERAGEX(table, expression)

The function has the following parameters:

Example: Basic AVERAGEX with a calculated value.

DAX

AVERAGEX Measure =
AVERAGEX(
    MarksTable,           -- Table to iterate over
    MarksTable[Marks]     -- Expression to evaluate and average
)      

This is like AVERAGE(MarksTable[Marks]). The output of the above code is shown below:

AVERAGEX DAX Function in Power BI

Example: Average Marks per Subject Category.

To calculate the average of total marks, but per Subject category.

DAX

AVERAGEX Marks per Subject =
AVERAGEX(
    VALUES(MarksTable[Subject]),       -- Get a unique list of subjects
    CALCULATE(SUM(MarksTable[Marks]))  -- Calculate total marks for each subject
)    

The output of the above code is shown in the image below:

AVERAGEX DAX Function in Power BI

Explanation:

Goal of this DAX: Find the average of total marks per subject.

  1. Get all unique subjects.
  2. For each subject, calculate the total marks scored.
  3. Average those subject totals.

Step-by-Step Backend Breakdown:

Step 1: VALUES(MarksTable[Subject])

Step 2: AVERAGEX Iterator Starts

Step 3: CALCULATE(...) Converts Row Context → Filter Context

Step 4: AVERAGEX Averages These Totals

Behind the Scenes: Row Context vs Filter Context

Alternative with Measure:

Instead of using CALCULATE, create a measure (measures inherently work in filter context):

DAX

Total Marks Measure = SUM(MarksTable[Marks])

The above measure can be used in our calculation.

DAX

AVERAGEX Marks per Subject =
AVERAGEX(
    VALUES(MarksTable[Subject]),       -- Get a unique list of subjects
    [Total Marks Measure]  -- Calculate total marks for each subject
) 

AVERAGE vs. AVERAGEX

Choosing the right function depends on your data structure and calculation needs: