Future-Proof Your Career, Master Data Skills + AI

Blog

Blog

# DAX Power BI: What Is Row Context

by | 7:00 pm EST | November 17, 2020 | DAX, Power BI

In this blog, we are going to dive into row context in DAX Power BI. Another way to call it is the iterating calculation engine, but it is called row context from a more technical perspective. You may watch the full video of this tutorial at the bottom of this blog.

## DAX Power BI: Row Context & SUMX

The way that you get into row context is by using iterating functions in Power BI such as SUMX. SUMX returns the sum of an expression evaluated for each row in a table.

The second parameter of SUMX is the expression which stands for any logic that works with the table that we specify.

Following this example, remember how we generated this measure?

What happened first is that the evaluation context is applied. Afterwards, we jumped into the Sales table behind the scenes after every individual result.

After that, we ran some logic in every single row of that table and saved them in memory. Then, from those results in the memory, we finally summarized everything to get the results in the Total Sales column.

With this in mind, you can actually get really advanced with your expressions.

You can write IF statements or SWITCH statements, or any type of logic that can be done in a single row within an iterating function like SUMX.

SUMX is not the only iterating function we can use. There are also functions like AVERAGEX and MINX where calculations are also done in row context.

The iterating engine is more comprehensive than the filter context because it looks at everything left over in a column after all the filters are in place.

## Row Context On Total Quantity

You can see here that we have our Total Quantity measure which takes the sum of the Quantity column.

We can actually calculate the same result using row context instead of filter context.

For this, we can create a new measure called Total Quantity (Iteration), use SUMX, and then put in the Sales table while referencing the Quantity column.

After that, we can now bring in our new measure for comparison. We are simply calculating exactly the same result for the two measures.

However, the results were calculated by using two different calculation engines in Power BI – the one on the left uses filter context while the other uses row context.

Although there is not much of a difference when working with simpler models, more computations are happening inside iterating functions.

If you will be working with much larger data sets and models, it is better to use the SUM function instead of SUMX. The earlier example was only for the sake of comparison, so it is unnecessary to overload the calculation more than needed.

However, for calculating something like the Total Sales, it is necessary to use an iterating function since there was no way we could calculate it using SUM based on the data that we had.

These are things that you should think about. Hopefully, it is more clear to you what is happening behind the scenes on these calculations.

## DAX Power BI: Iterating Functions Vs Aggregating Functions

Based on personal experience, when I used Microsoft Excel, I never really had to think about what is going on with the calculation engines when running calculations.

But in Power BI, you need to think about when it is best to use an iterating function or an aggregating function. This gets more complex as you use more advanced formulas and combine them together.

With this in mind, it is important to get a good grasp of these concepts before you move on to more complex things like cumulative totals or moving averages.

## Conclusion

Power BI is amazing because of all the high-quality analytics it is capable of, and it all starts with a good understanding of the row context.

Even with the more advanced stuff, you should think about the context of a particular result to understand what is being calculated.

That is all I wanted to cover with regard to iterating functions in Power BI. Next, we’ll go over additional things to consider about context.

All the best,

Sam

## How to Calculate Age in Excel: 5 Best Methods Explained

Looking to calculate age in Excel? Well, you're in the right place. Whether you need to find the age of...

## Funny ChatGPT Prompts: 20 Hilarious ChatGPT Ideas

In a world where technology continues to amaze us, we have now arrived at the point where we can have a...

## Power BI Slicer Search: User Guide With Examples

Ready to get started with the Power BI slicer? This feature will allow you to filter and slice your...

## How to Move Files in SharePoint: Top 4 Methods Explained

Struggling to move Files in SharePoint? Don't worry, we've all been there. Knowing how to move files...

## How to Return List in Python: 3 Top Methods Explained

The return statement plays a pivotal role in Python. It’s what lets your functions communicate with the...

## How to Create P Value in Excel? A Step-by-Step Guide

Ready to create a P value in Excel? Want to learn how to quickly and efficiently do it? Read on. To...

## How to Strikethrough Text in Excel? Easy Guide + Examples

Want to strikethrough some text in your Excel document but don’t know how? Don’t worry, it's easy, read...

## How To Calculate Z-Scores in Excel? User Guide with Examples

Ready to calculate a z-score in Excel? Awesome. Because we are going to show how to do it quickly and...

## Top 20+ Data Visualization Interview Questions Explained

So, you’re applying for a data visualization or data analytics job? We get it, job interviews can be...

## Top 10 Free Datasets for Statistics Projects

Are you looking for a way to explore and analyze real-world data to enhance your understanding of...

## How to Calculate Standard Error in Excel? Top 3 Methods

The standard error is a key statistical tool that allows you to assess the accuracy and reliability of...

## How to Delete a SharePoint Site: 4 Best Methods Explained

Ready to delete your SharePoint site? It really is as easy as 1,2,3 and 4! To delete a SharePoint site:...