DAX HANDBOOK
3. Iterative functions

If you wish to follow along, you can find PBIX/Excel files at the bottom of the article. 

Authors

Krešimir Ledinski

Krešimir Ledinski

Microsoft certified expert in the field of Business Intelligence. His biggest passions are DAX, M, and data modeling.

Kristian Radoš

Kristian Radoš

Experienced data analyst. Advanced in SQL, PowerApps and M language.

Iterative functions have one special ability, and that is to form a “Virtual” row context for the table supplied as an argument.

Table vs Scalar Iterative Functions

The most used iterative functions are:

  • SUMX, MINX, MAXX, AVERAGEX, CONCATENATEX, COUNTX, RANKX
    • Pretty much any function ending with X
    • All those functions have 2 things in common, they form row context and return a scalar value
  • FILTER, ADDCOLUMNS, SUMMARIZE, GENERATE etc.
    • These functions create row context, but instead of scalar value, they return modified tables as result.

In this chapter, we will focus on the “X” group of iterators, while table iterators will be covered in the next chapter. 

Syntax


Almost all “X” type iterators have the same syntax which we will explain with the [SalesAmountCorrect] measure. We will again focus on the first row in a visual filtered by the Black color.
SalesAmountCorrect = SUMX(Sales,Sales[Price]*Sales[QTY])

This image has an empty alt attribute; its file name is DAX-Iterative-functions-1.jpg
  1. The original filter context is formed with the condition Sales[Color] = “Black”
    • Source table gets filtered to contain only sales of color “Black”
  2. After the table has been filtered by the original filter context, the calculation starts.
    SUMX accepts 2 arguments:
    • First argument (Sales), is the table upon which we wish to create row-by-row calculation (row context)
      • Sales table is not the whole table, but the one already filtered by the original filter context!
        o We can picture this as a filtered Sales table to which we add a “Virtual” column called X
    • The Second argument of SUMX function is the calculation that will be performed in the virtual X column, respecting row-by-row rules of iteration.
      • In our example, the calculation that should be performed row-by-row is Sales[Price]*Sales[QTY]
      • Notice that we didn’t need to use any aggregation (such as SUM) since the X part of the calculation operates in a row context, meaning Sales[Price] can only reference the current row of the iteration. This applies to all rows of the X column.
  3. Once the iteration finishes and the virtual X column computes the row-by-row calculation, the SUM part of the SUMX function starts. It sums up all the computed values of the virtual X column.

Explanation of X in Iterative Functions

The X part works the same for all X types of iterative functions. The only part that differs is the function prefix before X.

  • SUMX will return the sum of the virtual X column
  • MINX will return the min of the virtual X column
  • CONCATENATEX will return the string of X column values combined

Iterators that return scalar values are a great replacement for calculated columns with simple logic, such as column1 +-*/ column2, as well as any kind of Calculated Column of Value type. Calculated columns should still be used in case we wish to create Filter types of columns (e.g. the ones we wish to plot on visual as filters, since Measures itself cannot be used to create the original filter context).

Materials

We wish to create the best possible content!

If you are a novice looking for a better explanation of any element of the topic, feel free to comment on the part you didn't quite understand!

If you are an expert in DAX and believe certain topic lacks important internals, your comments are more than welcomed!

COMMENTS

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

OUR SERVICES

Prefer live training or consultations?

Table of Content

Table of Content

GET LATEST BI NEWS TO YOUR INBOX

Receive the latest updates on all business analyst news across all platforms.

By subscribing you are agreeing to our Privacy Policy.

Related blog posts

Held PowerApps training for Žito d.d.

Last week we went to Osijek to hold a PowerApps training for Žito d.d. The training took place at the client’s office, lasting 2 days, with a total duration of 8 hours. The participants of the training have been using PowerApps in their business for some time, but they wanted...

Read more

Održana PowerApps edukacija za Žito d.d.

Prošli tjedan svratili smo do Osijeka kako bismo održali PowerApps edukaciju za Žito d.d. Edukacija se održala u 2 dana kod klijenta u uredu, u sveukupnom trajanju od 8 sati. Polaznici edukacije već neko vrijeme koriste PowerApps u svom poslovanju, no željeli su usavršiti svoje vještine u samostalnoj izradi aplikacija,...

Read more

This year’s first PowerApps training for TÜV NORD Adriatic

Last week we held this year’s first PowerApps training for our long-term clients from the TÜV NORD Adriatic company. It was a full-day education lasting 6 hours, led by our PowerApps expert and developer Kristian! The PowerApps platform is intended for the creation of customized business applications and enables the...

Read more

Prva ovogodišnja PowerApps edukacija za TÜV NORD Adriatic

Prošli tjedan održali smo prvu ovogodišnju PowerApps edukaciju za naše dugogodišnje klijente iz TÜV NORD Adriatic kompanije. Bila je to cjelodnevna edukacija u trajanju od 6 sati, koju je vodio naš PowerApps stručnjak i developer Kristian! PowerApps platforma namijenjena je izradi prilagođenih poslovnih aplikacija i omogućava brzi razvoj aplikacija koje...

Read more
0
Would love your thoughts, please comment.x
()
x
Scroll to Top