Row Context vs. Filter Context | Power BI || Belayet Hossain

Row Context vs. Filter Context | Power BI || Belayet Hossain

?? 1. Filter Context

Filter context is the context that comes from filters applied to your data. These filters can come from slicers, visuals, or explicitly from DAX expressions that modify what data is visible or considered in a calculation.

How it works:

  • Filter context operates at a data level based on the selected or filtered values in your report.
  • It can apply to multiple rows of data, and it defines which rows are visible for a particular calculation.
  • Think of it as the external condition that controls which data is being evaluated.

Example:

You have a table with sales data, and you apply a slicer to show only sales for 2023. This slicer creates a filter context, so only rows related to 2023 are included in the calculation.

Use in DAX:

  • Filter context is automatically applied to measures.
  • You can modify filter context using functions like CALCULATE(), FILTER(), and REMOVEFILTERS().

Visual Example:

  • If you apply a slicer to show only sales for 2023, the filter context will only consider the rows for 2023 (ignoring the rows from 2022).
  • Any measure that calculates total sales will only include the visible rows for 2023.


?? 2. Row Context

Row context refers to the current row that DAX is evaluating. It’s specific to each individual row, meaning DAX processes calculations on a row-by-row basis when creating calculated columns or working with certain functions.

How it works:

  • Row context only applies to one row at a time, where each row is evaluated independently.
  • It exists whenever DAX works inside a calculated column, iterates over tables, or uses iterating functions like SUMX(), AVERAGEX(), or RANKX().

Example:

If you are calculating the profit margin for each sale in a table, DAX would use the row context to calculate the margin for each individual row.

Use in DAX:

  • Calculated columns inherently work with row context.
  • Functions like SUMX(), FILTER(), and RANKX() introduce row context because they evaluate each row of a table individually.

Visual Example:

To calculate profit (Sales - Cost), you use row context to evaluate each row individually.


?? Differences Between Filter Context and Row Context


?? Bringing Them Together

When writing DAX, row context and filter context can interact. For example, CALCULATE() modifies the filter context to change what rows are being considered, while iterating functions like SUMX() introduce a row context to calculate results for each row individually.


#PowerBI #filtercontext #rowcontext

要查看或添加评论,请登录

Belayet Hossain的更多文章

社区洞察

其他会员也浏览了