In this post, I expand more on the evaluation context in Power BI DAX. You may watch the full video of this tutorial at the bottom of this blog.
Evaluation context is also known as the initial context in Power BI. It is the environment from which your calculation is based on.
To make things more advanced, can your formulas actually have multiple contexts working at the same time?
Changing Context Within A Formula
Having multiple contexts is not that complicated, and I will show you this through an example.
First of all, we need to always understand what the evaluation or initial context is.
You need to have a great understanding of how context works within your formula.
Otherwise, you would sometimes have no idea where your results are coming from eventually.
In this example, the evaluation context is rather simple since it is simply the contents of the table.
But what if I wanted to calculate a running total here?
To do this, I will create a measure first and call it 30 Day Running Total. Then, I will put a CALCULATE function in my next line.
I will cover the CALCULATE function in detail in a later section, but essentially it calculates any expression we put inside and allows us to change the context of the calculation within a measure.
CALCULATE will become your most used function by far since it is the most important function in DAX.
To proceed, I am going to calculate the Total Sales column but I want to calculate it in a different context.
I will use the FILTER function which allows me to create a filter in the new context that I want.
FILTER allows me to put a table inside it, but you do not have to put an actual table since you can also use a table function like in this example.
I will then bring in the new measure to the table and put it in visualization for easier understanding.
Logically speaking, we get the running total for each specific day by looking back from that day to thirty days prior and then summing all of them up.
This is important with regards to context since we have the evaluation context first through the Date column, but then we change the context to calculate the Total Sales in a new environment through a formula.
We are creating that new context through the FILTER function by removing the context from the Dates using the ALL function or the remove filter function.
After removing the filter from any date, I will then work through every single date and look at the thirty day window from that specific date through this part.
You can now see that we have created a different context within the formula itself.
Importance Of Understanding Evaluation Context
Understanding the evaluation context at every single point in time is very important. It gets more advanced since there are a lot of ways that we can change the context to calculate something different.
However, as you get deeper into Power BI, it also opens up a new world of opportunities where your formulas would not unnecessarily be long and complex.
Knowing these concepts would enable you to write things more efficiently wherein complex calculations could be done with a simple formula.
This article is simply an introduction about how you can change the context to write efficient formulas.
There are a lot of applications for context so hopefully, you are excited to see what you can achieve through the formula combinations and patterns that you can create.
Let us round off this section and move on to more key ideas and functionalities when utilizing DAX functions.
All the best,
***** Related Course Modules *****
Ultimate Beginners Guide To DAX
Mastering DAX Calculations
Solving Analytical Scenarios With Power BI And DAX
***** Related Support Forum Posts *****
Filter Context And Row Context
Why Do You Need Change Context With Calculate When Using A Measure
Struggling With Context
For more understanding context queries to review see here…..