The Iterator Edition

By Audrey Gerred

Let’s talk about some DAX functions! More specifically, I want to unravel the difference between iterator DAX functions and their regular counterparts. Admittedly, this is something that I didn’t get the importance of right away. It’s a bit like comparing apples to oranges, but both are delicious in their own way.

First Things First: DAX Functions

DAX (Data Analysis Expressions) is the language used in Power BI (Power Query uses M code, i.e. Mash-Up). It has a wide array of functions to perform calculations, aggregations, and transformations. Some functions are pretty straightforward – you give them a column of data, and they return a single value.

What the Heck are Iterator Functions?

Then, there are these special ones called iterator functions. They’re like wizards in the world of DAX. Instead of dealing with the whole column at once, they work their magic row by row, giving you the power to iterate (i.e. doing it again and again – see, row by row) through your data.

AVERAGEX vs. AVERAGE: The Showdown

Let’s take an example to understand the difference between iterator functions and regular functions, and when to use which.

Scenario: Daily Sales Data

You have a dataset with daily sales data, and you want to calculate the average sales amount. Now, you could use the AVERAGE function, and it would work just fine. It takes the whole column of sales amounts and gives you the average.

Average Sales = AVERAGE(SalesTable[SalesAmount])

The Twist: Monthly Average

But here’s the twist: What if you want to calculate the average monthly sales, and your data is in a detailed daily format? AVERAGE alone won’t cut it because it would give you an average of all the daily values. You need a monthly breakdown.

AVERAGEX to the Rescue!

This is where AVERAGEX comes into play. It’s an iterator function. Instead of taking the entire column in one go, it works through each row and then calculates the average. So, it goes through each row to do the summing, then averaging the sums.

Average Monthly Sales = AVERAGEX(SalesTable, SalesTable[SalesAmount])

Here’s the key: by using AVERAGEX, you’re able to iterate through the daily data and calculate the monthly average. It’s like having a mini AVERAGE function for each month, and then you’re getting the average of those monthly averages. This makes your calculation precise and granular, exactly what you need for monthly insights.

Conclusion: Choose the Right Tool for the Job

The takeaway here is simple: choose the right tool for the job. When you need a quick, straightforward average, use AVERAGE. But when you need to dive into the details, perform calculations row by row, and get more granular results, that’s where AVERAGEX and its iterator friends come in handy.

The next time you’re faced with a data challenge, remember that DAX has a toolkit with functions that cater to your specific needs. Choose wisely, and you’ll be the magician of your data analysis!

Here’s a Microsoft Learning path that can help you dig in further: Use DAX iterator functions in Power BI Desktop models – Training | Microsoft Learn


Leave a comment