There are mainly two types of evaluation context in DAX: Filter context and Row context.
The filter context is the set of filters applied to the data model before the evaluation of a DAX expression starts. Filter Context always exist before a DAX expression been evaluated.
Some initial level filters context applied on Power BI report page in form of:-
- Filter through other Visual
- In Matrix visual based on Row and column data fields
- Power BI filters
A Row context is evaluated whenever an expression iterates over a table. Each individual row in a table has its own row context.
A row context exists in either a calculated column or an iterating DAX functions such as SUMX, AVERAGEX, FILTER & ADDCOLUMNS etc.
If you have created a calculated column, the row context consists of the values in each individual row and values in columns that are related to the current row.
To calculate the Total Sales, multiply the Quantity by the Sales of each category in a newly created column named TotalSales.
As you are aware, a calculated column performs row-by-row calculations (row context), and you can view the results in the screenshot below.
Filter Context and Row Context in same DAX formula
Sample dataset as below:
Step-1: Create a measure and write DAX code below.
Total Sales = SUMX( FILTER('Product', 'Product'[Region]="A") , 'Product'[Sales] * 'Product'[Qty])
It is filtering the table for each row where Region is “A” and multiplying sales by quantity.
Step-2: Drag the new measure into the Table visual to see the final output. It will return the value only for Region ‘A’ with the specified condition.
Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome or you can leave us message on our Contact form , we will revert to you asap.