Iterator Functions (X Functions)

Learn how DAX iterator functions evaluate expressions row by row using functions such as SUMX, AVERAGEX, COUNTX, MINX, and MAXX.

Iterator Functions (X Functions)

Iterator functions evaluate an expression one row at a time before returning a final result.

Unlike simple aggregation functions such as SUM() or AVERAGE(), iterator functions perform a calculation for every row in a table.

Because they evaluate rows individually, iterator functions automatically create row context.

Common iterator functions include:

  • SUMX()
  • AVERAGEX()
  • COUNTX()
  • MINX()
  • MAXX()
  • RANKX()

Iterator functions are among the most powerful tools available in DAX.


What Is an Iterator?

An iterator processes one row at a time.

General syntax:

SUMX(
    Table,
    Expression
)

Unlike SUM(), which simply adds an existing column, SUMX() first evaluates an expression for every row.

After every row has been calculated, the results are added together.


SUM vs SUMX

Consider this measure:

Total Sales =
SUM(FactSales[SalesAmount])

This adds the values already stored in the SalesAmount column.

Now compare it to:

Total Sales =
SUMX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

Instead of summing an existing column, SUMX() calculates:

Quantity × Unit Price

for every row before calculating the final total.


How SUMX Works

Power BI evaluates each row individually.

Row 1

Quantity × Unit Price



Row 2

Quantity × Unit Price



Row 3

Quantity × Unit Price



...



Add Every Result



Final Total

This row-by-row evaluation makes iterator functions extremely flexible.


Example Data

Suppose FactSales contains:

ProductQuantityUnit Price
Tire A550
Tire B375
Tire C840

Using:

SUMX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

Power BI calculates:

ProductCalculation
Tire A250
Tire B225
Tire C320

Final result:

250 + 225 + 320 = 795

No SalesAmount column is required.

The calculation is performed dynamically.


Why Use Iterator Functions?

Iterator functions allow calculations that simple aggregation functions cannot perform.

Typical uses include:

  • Revenue calculations
  • Weighted averages
  • Profit calculations
  • Ranking
  • Dynamic scoring
  • Complex business rules

Whenever every row requires its own calculation, an iterator is usually the correct choice.


AVERAGEX()

AVERAGEX() evaluates an expression for every row and then returns the average.

General syntax:

AVERAGEX(
    Table,
    Expression
)

Example:

Average Revenue Per Sale =
AVERAGEX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

Instead of averaging an existing column, AVERAGEX() first calculates revenue for each row and then averages the results.


COUNTX()

COUNTX() evaluates an expression for every row and counts the non-blank results.

Example:

Orders With Sales =
COUNTX(
    FactSales,
    FactSales[SalesAmount]
)

This returns the number of rows that contain a sales value.


MINX() and MAXX()

MINX() and MAXX() evaluate an expression for each row before returning the smallest or largest value.

Example:

Highest Order Value =
MAXX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

Example:

Lowest Order Value =
MINX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

These functions are useful when the value being compared is calculated rather than stored.


RANKX()

RANKX() ranks rows based on an expression.

Example:

Product Rank =
RANKX(
    ALL(DimProduct),
    [Total Sales]
)

This measure ranks every product based on total sales.

Example output:

ProductSalesRank
Tire A$450,0001
Tire B$325,0002
Tire C$210,0003

RANKX() is commonly used for Top N reports and leaderboards.


Combining FILTER() with SUMX()

Iterator functions are often paired with FILTER() to evaluate only selected rows.

Example:

Large Order Sales =
SUMX(
    FILTER(
        FactSales,
        FactSales[SalesAmount] > 1000
    ),
    FactSales[SalesAmount]
)

Evaluation process:

FactSales



FILTER()



Only Orders > $1,000



SUMX()



Total Sales

This pattern is extremely common in advanced DAX.


Real Business Examples

Iterator functions solve many practical business problems.

Business QuestionFunction
Total RevenueSUMX()
Average Order ValueAVERAGEX()
Number of Valid OrdersCOUNTX()
Largest SaleMAXX()
Smallest SaleMINX()
Top-Selling ProductRANKX()

Many financial and operational reports rely on iterator functions because they calculate values dynamically rather than relying on stored columns.


Why Iterator Functions Are Powerful

Simple aggregation functions operate on existing values.

Iterator functions evaluate expressions.

Compare these examples:

SUM(
    FactSales[SalesAmount]
)

versus

SUMX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

The second measure performs a calculation for every row before producing the final result.

This flexibility is what makes iterator functions some of the most powerful tools in DAX.


Performance Considerations

Iterator functions are extremely powerful, but they perform more work than simple aggregation functions.

Unlike SUM(), which simply totals an existing column, functions such as SUMX() evaluate an expression for every row before returning a result.

Example:

FactSales

100,000 Rows



Evaluate Expression



100,000 Calculations



Return Total

For large tables, this additional processing can increase query execution time.

Whenever possible, choose the simplest function that satisfies the business requirement.


SUM() vs SUMX()

A common question is when to use SUM() instead of SUMX().

Use SUM() when the values already exist in a column.

Example:

Total Sales =
SUM(FactSales[SalesAmount])

Use SUMX() when each row requires a calculation.

Example:

Total Sales =
SUMX(
    FactSales,
    FactSales[Quantity] *
    FactSales[Unit Price]
)

Decision Guide

If you need to...Use
Add an existing columnSUM()
Calculate each row firstSUMX()
Average an expressionAVERAGEX()
Rank rowsRANKX()
Count calculated valuesCOUNTX()

As a rule of thumb:

If the calculation already exists in a column, use a standard aggregation function.

If every row must be evaluated first, use an iterator function.


Common Beginner Mistakes

Avoid these common issues:

  • Using SUMX() when SUM() would produce the same result.
  • Creating calculated columns instead of using iterator functions.
  • Forgetting that iterator functions create row context.
  • Performing expensive calculations on very large tables unnecessarily.
  • Nesting multiple iterator functions without understanding the performance impact.

Iterator functions are powerful, but they should be used intentionally.


Best Practices

When working with iterator functions:

  • Use iterator functions only when row-by-row calculations are required.
  • Create reusable base measures whenever possible.
  • Use variables (VAR) to simplify complex expressions.
  • Filter data before iterating whenever practical.
  • Test performance when working with large fact tables.

Keeping calculations simple improves both readability and report performance.


Summary

Iterator functions evaluate expressions one row at a time before returning a final result.

Common iterator functions include:

  • SUMX()
  • AVERAGEX()
  • COUNTX()
  • MINX()
  • MAXX()
  • RANKX()

Because they create row context, iterator functions can perform calculations that standard aggregation functions cannot.

Understanding when to use iterator functions is an essential skill for writing advanced DAX.


Next Steps

Continue learning DAX with one of the most widely used feature sets in Power BI:

  • Time Intelligence
  • SUMX — a deeper look at the most commonly used iterator, including when SUM is actually the better choice.

After mastering Time Intelligence, you'll be ready to build running totals, year-over-year comparisons, rolling averages, and many other advanced business calculations.