top of page

Power BI Row Context and Filter Context

Updated: 6 days ago

By - Shivanee Sharma What is Context in Power BI? 

In Power BI, context means the conditions that affect how calculations work. It helps decide which data is used when running formulas. Understanding context is important for writing correct DAX formulas and getting accurate results in reports. There are two primary types of contexts in Power BI: Row Context and Filter Context

 

1. Row Context 

Definition: Row context is when Power BI looks at one row at a time in a table while doing a calculation. It automatically happens when you're working with calculated columns or functions that go through each row, like SUMX, AVERAGEX, MINX, MAXX, FILTER, etc.  Row context refers to the situation where Power BI evaluates an expression one row at a time within a table—but does so for each row. This context is automatically created in calculated columns and in functions like SUMX, AVERAGEX, FILTER, etc., which iterate over a table. While each row is processed individually, the calculation ultimately includes all rows (one by one). 

 

Example: Consider a table named Sales with columns Quantity and Price. To calculate the total revenue for each row, we use the following DAX formula: 

Profit = Sales[GrossSale]- Sales[NetSales] 

 

 

Spreadsheet displaying sales data. Columns include Country, Product, QtySold, Year_of_Sales, SalesDate, GrossSale, NetSales, and Profit. Formula: Profit = Sales[GrossSale] - Sales[NetSales].

 

 

Here, the multiplication occurs row by row because row context is applied automatically. 

 

When Row Context is Used: 

  • When using calculated columns. 

  • When iterating through a table using X functions (like SUMX, AVERAGEX, etc.). 

  • When using row-based operations in measures

 

2. Filter Context 

Definition: Filter context refers to the set of filters applied to a calculation before evaluation. It is influenced by slicers, filters, and relationships in the data model. 

 

Example: Consider a measure that calculates the sum of sales: 

Total Sales = SUM(Sales[Revenue]) 

If we apply a filter (e.g., filtering only for "USA" in the Country column), the SUM(Sales[Revenue]) measure will only sum values where the country is "USA". 

 

 

How Filter Context Works: 

  • Slicers and Filters: When you apply a slicer on a report (e.g., filtering by year 2023), the measure automatically calculates only for the filtered data. 

  • Visualizations: Different visuals (e.g., bar charts, tables) apply filters dynamically based on selected fields. 

  • DAX Functions (CALCULATE, ALL, REMOVEFILTERS): You can modify filter context using functions like CALCULATE, which changes how filters are applied. 

 

TotalSales_USA = CALCULATE(SUM(Sales[Profit]),FILTER(ALL(Sales), Sales[Country] = "USA")) 

 

Code snippet calculates total sales for the USA. A table shows sales data for CPU, Pen, and Shampoo. A country filter lists several options.

  

This measure forces the filter context to always consider only USA sales, regardless of other filters. 

 

Row Context vs. Filter Context 

 

Feature 

Row Context 

Filter Context 

Applied to 

Individual rows 

Filtered data set 

Created by 

Iterative functions (X functions) 

Slicers, filters, relationships 

Example Function 

SUMX, FILTER 

CALCULATE, ALL 

Can Modify? 

No, unless used inside CALCULATE 

Yes, using CALCULATE and filter functions 

 

Conclusion 

  • Row context is used when Power BI calculates values one row at a time, such as in calculated columns or when using functions like SUMX. 

  • Filter context decides which data should be included in a calculation based on filters, slicers, visuals, and relationships in your data model. 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page