Iterators (SUMX, AVERAGEX)0%

Iterators (SUMX, AVERAGEX)

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

DAX Iterators: Row-by-Row Evaluation with SUMX, AVERAGEX & RANKX

Standard aggregation functions (SUM, AVERAGE, MIN, MAX) take a single column as input and aggregate all visible values in that column under the current filter context. However, real-world business formulas frequently require calculating values row-by-row before aggregating—this is the domain of DAX Iterators (commonly known as the "X-Functions").


1. Aggregators vs. Iterators

FeatureStandard Aggregators (SUM, AVERAGE)Iterators (SUMX, AVERAGEX, MAXX, MINX)
SyntaxSUM(Table[Column])SUMX(Table, RowExpression)
InputA single column referenceA table (or table expression) AND a scalar row calculation
Evaluation MechanismOperates strictly across the pre-existing columnIterates row-by-row, computes the expression in Row Context, then aggregates
Memory EfficiencyHigh (native columnar scan)High (avoids creating permanent calculated columns in memory)
Output
The SUMX Execution Pipeline:
Table: Fact_OrderItems (Rows 1 to N)
[Row 1]: Qty (2) * UnitPrice ($50) * (1 - Discount 0.10) = $90
[Row 2]: Qty (1) * UnitPrice ($120) * (1 - Discount 0.00) = $120
[Row 3]: Qty (5) * UnitPrice ($10) * (1 - Discount 0.20) = $40
|
+---> VertiPaq sums the results: $90 + $120 + $40 = $250!

2. Implementing SUMX: Dynamic Revenue Calculation

Instead of polluting your data model with a calculated column for line total, compute it dynamically:

DAX
-- Total Net Sales using SUMX
Total Net Sales =
SUMX(
Fact_OrderItems,
Fact_OrderItems[Quantity] * Fact_OrderItems[UnitPrice] * (1 - Fact_OrderItems[DiscountRate])
)

Filtering Inside an Iterator

Because the first argument of an iterator is any valid Table Expression, you can combine iterators with FILTER:

DAX
-- High-Value Order Sales (Orders with Sales > $1,000)
High Value Sales =
SUMX(
FILTER(
Fact_OrderItems,
Fact_OrderItems[UnitPrice] > 1000
),
Fact_OrderItems[Quantity] * Fact_OrderItems[UnitPrice]
)

3. Dynamic Ranking with RANKX

RANKX evaluates a table and ranks each row dynamically according to a measure:

DAX
-- Rank Products by Sales
Product Sales Rank =
IF(
ISBLANK([Total Sales]),
BLANK(),
RANKX(
ALL(Dim_Product[ProductName]),
[Total Sales],
,
DESC,
Dense
)
)

RANKX Parameter Breakdown

  1. 1
    Table (ALL(Dim_Product[ProductName])): The list of all items to be ranked. Using ALL removes outer row filters so each product is compared against all products.
  2. 2
    Expression ([Total Sales]): The metric used for ranking.
  3. 3
    Value (Omitted): Evaluates the expression for the current item.
  4. 4
    Order (DESC): Highest sales receives Rank 1.
  5. 5
    Ties (Dense): Tied ranks do not skip numbers (e.g., 1, 2, 2, 3 instead of 1, 2, 2, 4).

4. Performance Considerations for Iterators

  • Iterators introduce Row Context. When nesting iterators inside other iterators (e.g., SUMX(..., AVERAGEX(...))), the VertiPaq engine must perform quadratic loop iterations, which can degrade report speed on datasets with millions of rows.
  • Always filter tables as early as possible using the smallest table expression in the first parameter.

Interactive Quiz

Multiple Choice Questions

Question 1
What is the fundamental difference between SUM(Table[Sales]) and SUMX(Table, Expression)?
Question 2
In the formula SUMX(Fact_Sales, Fact_Sales[Qty] * Fact_Sales[Price]), what context is created by SUMX to evaluate Qty * Price?
Question 3
Why is using ALL(Dim_Product[ProductName]) inside RANKX essential when ranking products in a table visual?
Question 4
What tie-breaking method in RANKX assigns consecutive ranks (e.g., 1, 2, 2, 3) without skipping rank positions?
Question 5
Why is replacing multiple Calculated Columns with a single SUMX measure considered a Power BI performance best practice?

Next Lesson

CALCULATE and FILTER Functions

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext