Evaluation Context In DAX Calculations

In this tutorial, we’ll learn about evaluation context in DAX.

Evaluation or initial context is the environment from which your dynamic calculation is based from.

It’s important to understand how evaluation context works and how it affects your DAX calculation. So in the next section, I want to show you the different ways to create the evaluation or initial context.

Creating Evaluation Or Initial Context In DAX

First, you need to have a Date slicer and City filter in your table to achieve dynamic data.

There’s always an initial context that you need to be aware of before doing any calculation. You can find the said evaluation context from any location.

In the sample table, the context can be found from the Date slicer or from the City filter. For example, if you select the Christchurch filter, the results in the table will change. If you also adjust the dates from the 1st of January to the 19th of January, you can see that the results changed.

For example, for the 1st of January, the result is 90,074.80 while on the 19th of January, it’s 111,293.70. This proves that evaluation context can really change for every single result in DAX calculations.

To show you another example, let’s turn the existing table into a Total Sales by Date visualization.

When you select or clear a filter or even adjust the time frame, you can get a new result inside the visualization.

The key thing to note is that the formula that we are using in this table and visualization doesn’t change. It is exactly the same formula.

In Excel, every single formula you see will be slightly different because the cell references will be different. In Power BI, the formula stays exactly the same. What changes the result is the context or the environment in which it is evaluated. This applies for every measure you create.

Every calculation you do within Power BI has an initial context that you need to understand. Before you look at any individual result, you need to understand the current context of that calculation.

If you didn’t know what was selected in the city slicer, you would be looking at this visualization and know that this is the Total Sales by Date. But what kind of Total Sales is it?

In the example below, you’ll know that the total sales displayed in the visualization are from Hamilton based on the slicer.

Relationship Between Context And Data Model

Understanding how this context works is a crucial part of learning and understanding DAX – because this is as easy as it gets. You can then start manipulating the context within formulas and start doing some advanced analysis.

Hopefully, you’re also starting to see how important the model is because the context is directly created by the relationships among your tables.

The city slicer that we are selecting is from the Regions table while the calculation of Total Sales is in the Sales table.

This is called filter propagation.

Filters propagate down the relationship through the arrows and they head towards the many sides on the fact table, which is the Sales table in this case.

You can do as many of these things at any one time because the context can come from one lookup table and another lookup table. And then we could layer even more and create more context. We just have to understand what the initial context of the calculation is.

Conclusion

Filters and slicers are basic ways to create evaluation context in your DAX calculations.

I hope you understand just how important evaluation (initial) context is. If you want to do an advanced analysis later on, you’ll have to change the context within your formulas.

Cheers!

Sam

Sam McKay, CFA
Sam is Enterprise DNA's CEO & Founder. He helps individuals and organizations develop data driven cultures and create enterprise value by delivering business intelligence training and education.

Power BI Report Example For An Optical Dataset

A lot of you may know that we have an ongoing Power BI Challenge. One of our recent Power BI report...

AVERAGEX: Calculating Average Per Day In Power BI

Here I'm going to show you how to use the function AVERAGEX with DAX in Power BI. You may watch the...

Power BI Default Slicer Value Explained

One of the key features of Power BI is the slicer, which allows you to filter your data based on...

Format Data In Power BI: Addressing Irregular Data Formats

In today's blog post, we'll discuss Problem of the Week #6. I'll show you how to format data in Power...

Calculating A Rolling Average In Power BI Using DAX

In this tutorial, I’m going to show you how to calculate a dynamic Rolling Average in Power BI using...

Paginated Report In Power BI: An Introduction

In this tutorial, you’ll learn about paginated reports in Power BI. A paginated report is another name...

Creating Measure Tables & Subfolders In Power BI

For today's blog, I'll cover measure tables and subfolders. We're going to set up measure tables, and...

Ultimate Guide To Multiple IF Statements In Power BI

If you are looking to create more complex logic, then using multiple if statements in Power BI is a...

Highlight Highest & Lowest Values Using Quick Measure In Power BI

Quick Measures Pro is a powerful external tool to streamline data analysis and visualization in Power...

Power BI Desktop Update: The Charticulator Visual

Today, I would like to go over something that I found out by scrolling through Twitter. What I have...

How To Build a Portfolio And Showcase Your Data Projects to Employers

In today’s data-driven world, the ability to work with data has become an essential skill. Whether...

New vs Existing Customers – Advanced Analytics In Power BI

If you’re an online retailer or a high frequency sales operation, then understanding your customer...