AVERAGEX DAX Function in Power BI

The AVERAGEX DAX function evaluates an expression row by row over a table and returns the average (arithmetic mean) of those values.

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
)