What is Evaluation Context in DAX?

You are currently viewing What is Evaluation Context in DAX?

It is often confusing to understand evaluation context in a single day Power BI training. So we are planning a Power BI training in Sydney and Melbourne to focus solely on DAX. But until then, lets grasp a few basic concepts. Every DAX function is evaluated under a context. Evaluation context is an “environment” in which the formula is calculated. There are two types of evaluation contexts which are completely different from each other. In this blog, we have discussed the two evaluation contexts used in DAX. The concepts have been discussed with reference to Power BI desktop.

Row Context:

When you write an expression in a calculated column, the expression is evaluated for each row of the table, creating a row context for each row. In a similar manner, when you use an iterator like FILTER(), SUMX(), AVERAGEX(), ADDCOLUMNS(), or any one of the DAX functions that iterates over a table expression., it creates a row context.

A row context is evaluated whenever an expression iterates over a table. Row context does not follow relationships and does not create a filter context. DAX functions are used to covert a row context into a filter context.

Row Context in Power BI training

A row context exists in either a calculated column or an iterating function such as SUMX. It does not exist in a regular measure. This is because regular measures cannot be created using naked columns. Regular measures only operate on columns and tables so the row filtering does not come into play using measures unless the iterator function is used.

Filter Context:

Filter context is evaluated based on filtering applied on the data model in DAX. The Initial/Incoming filter context from

  • Slicers
  • Data Fields of a visual (e.g. Rows and Columns in Matrix)
  • Page or Report Filters
  • From other visualsFilter context can be modified or replaced by using Calculate function.  Filters otherwise automatically follows relationships from 1 to many side

Initial or Incoming Filter Context

The initial filters applied on the report in the form of slicers, page and report filters, visual filters act as the first-hand filtering before evaluation context is evaluated. 

Filter Context in Evaluation Context

Filter Context vs. Row Context

Two evaluation contexts taught in Power BI training in Sydney

The Rules for Evaluation

When a DAX expression is evaluated there are a series of rules that are executed in order. They form the foundation of how you will use DAX functions

The Rules for evaluation of DAX Expression are:

  1. Evaluation of the Initial/Incoming filter context from
    • Slicers
    • Data Fields of a visual (e.g. Rows and Columns in Matrix)
    • Page or Report Filters
    • From other visuals
  2. If CALCULATE () is used, Check for Filter modification.
  3. Check for applied filter to underlying table(s)
  4. Interpret the filter propagation per relationship(s)
  5. Evaluate the result.

This will be easier to understand once we create some expressions to demonstrate how the evaluation evolves.

There are many exceptions and variations to these rules but will intentionally overlook these nuances to make things simple and more generic. This will allow you to understand the most important fundamentals without getting bogged down by complex details.

All those exceptions to the rules are important but I believe you should only go these once you’ve spend enough time practicing these fundamentals and have deep understanding of it.

DAX Weekends-A Little Bit of Everything

Here’s a little bit of everything that we have discussed so far in DAX weekend blogs:

  • Filter Context is applied prior as the initial incoming filtering of data.
  • Row Context is applied to every record of the data table.
  • Calculated Columns create a row context.
  • Calculated Measures may or may not create a row context.
  • Since the calculated column create a row context, they can be created using naked column.
  • Calculated measures work on the principle of aggregation reflected by their name “measure” therefore, naked columns cannot be used for creating calculated measures.
  • DAX is a formula language that provides its user with different functions.

Are you a data analyst and want to learn more about Power BI? Why not sign up for Power BI training in Australia. We provide our services in the following regions

Leave a Reply