Filter context

The same measure shows a different number in every cell of a matrix. The reason is the filter context: the filters under which Power BI calculates that cell. Understand it and you understand DAX.

In short: every cell of a visual has its own filters: from its row and column, from slicers, from page and visual filters. These filters flow through the relationships to the fact table, and only then does the measure calculate. SELECTEDVALUE, HASONEVALUE and ISFILTERED read them.

Before this: IF and SWITCH, Column or measure?

Try it now

The measure in this exercise calculates nothing; it only shows which filter applies in the cell.

Task Make the filter context visible: create the measure "Selected Category" that shows the category each cell is filtered to, and "all" when several categories are in the filter.

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

Where the filters come from

  • Rows and columns of the matrix: the Hardware row filters Product[Category] to Hardware.
  • Slicers and other visuals on the page, through cross-filtering.
  • Filters in the Filters pane: on this visual, this page or all pages.

The total row has no filter from the rows, only the others. That is why it calculates with all categories, not with the sum of the rows above it. In the exercises here, clicking a number in the matrix shows which filters apply to it.

Reading the filter context

FunctionReturns
SELECTEDVALUE(column, alternate)the value when exactly one is left, otherwise the alternate (blank without one)
HASONEVALUE(column)TRUE when exactly one value is left
ISFILTERED(column)TRUE when the column is filtered directly

HASONEVALUE and ISFILTERED are not the same: a slicer with two categories selected filters the column (ISFILTERED is TRUE) but leaves two values (HASONEVALUE is FALSE).

Blanking the total row

Some KPIs make no sense in the total row, such as a classification or a rank. HASONEVALUE lets you keep the total row empty on purpose.

Task Sometimes the total row should stay empty. Create the measure "Sales without Total": [Total Sales], but only when exactly one category is in the filter, otherwise blank.

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

In real Power BI

  1. Create a matrix with Product[Category] in the rows.
  2. Add a measure with SELECTEDVALUE and put a slicer on the category.
  3. Select several categories in the slicer with Ctrl and watch what the measure shows in the total row.

Common mistakes

Expecting the total row to add up

It recalculates the measure with fewer filters. For sums the result is the same, for averages, shares and DISTINCTCOUNT it is not.

Mixing up row context and filter context

A calculated column has a current row but no filter from the report. SELECTEDVALUE in a column therefore does not react to slicers.

FAQ

How do I change the filter context in a formula?

With CALCULATE. That is the next lesson.

Do filters reach tables without a relationship?

No. Filters only travel along relationships, from the one side to the many side (or both ways if set).

Up next: CALCULATE

Changing the filter context yourself: the tool behind almost every KPI.

Next lesson

Write to us

Choose language

Select your preferred language