DAX filter functions: every one with an example

A reference of all DAX filter functions, CALCULATE, CALCULATETABLE, FILTER, ALL, ALLEXCEPT, ALLSELECTED, ALLNOBLANKROW, ALLCROSSFILTERED, REMOVEFILTERS, KEEPFILTERS, SELECTEDVALUE, LOOKUPVALUE, EARLIER, EARLIEST, and the window and visual calculation functions, each with what it does and a short example.

Short answer: DAX's filter functions change or read the filter context. CALCULATE and CALCULATETABLE evaluate an expression under changed filters. FILTER returns the rows that meet a condition. The ALL family (ALL, ALLEXCEPT, ALLSELECTED, ALLNOBLANKROW, ALLCROSSFILTERED, REMOVEFILTERS) removes filters, and KEEPFILTERS adds instead of replacing. SELECTEDVALUE reads a single selection, LOOKUPVALUE finds a value by keys, and EARLIER reaches an outer row. Microsoft's filter group also holds the window functions (OFFSET, INDEX, WINDOW, RANK, ROWNUMBER) and the visual calculation functions.

This page lists them all, with one example each, and links to the posts that explain the important ones in depth.

Which functions change the filter context?

FunctionDoesExample
CALCULATEevaluates a scalar expression with changed filtersCALCULATE ( [Revenue], 'Product'[Color] = "Red" )
CALCULATETABLEevaluates a table expression with changed filtersCALCULATETABLE ( VALUES ( Customer[Customer] ), 'Date'[Year] = 2026 )
FILTERreturns the rows of a table that meet a conditionFILTER ( VALUES ( Customer[Customer] ), [Revenue] > 10000 )
KEEPFILTERSmakes a filter intersect with existing filtersCALCULATE ( [Revenue], KEEPFILTERS ( 'Product'[Color] = "Red" ) )
Filter context functions

In depth: CALCULATE, FILTER, KEEPFILTERS.

Which functions remove filters?

FunctionReturns a table?DoesExample
ALLyesall rows or distinct values, ignoring filters; removes filters in CALCULATECOUNTROWS ( ALL ( 'Product' ) )
ALLEXCEPTyesremoves all filters on a table except the listed columnsCALCULATE ( [Revenue], ALLEXCEPT ( 'Product', 'Product'[Category] ) )
ALLSELECTEDyesremoves the visual's row and column filters, keeps slicersCALCULATE ( [Revenue], ALLSELECTED ( 'Product' ) )
ALLNOBLANKROWyeslike ALL, without the blank row of unmatched keysCOUNTROWS ( ALLNOBLANKROW ( 'Product' ) )
ALLCROSSFILTEREDnoclears all filters applied to a table, also those from other tablesCALCULATE ( [Revenue], ALLCROSSFILTERED ( Sales ) )
REMOVEFILTERSnoremoves filters from tables or columns; preferred for just removingCALCULATE ( [Revenue], REMOVEFILTERS ( 'Product' ) )
The ALL family

In depth: ALL, ALLEXCEPT and REMOVEFILTERS, ALLSELECTED.

Which functions read values?

FunctionDoesExample
SELECTEDVALUEthe value when exactly one is filtered, else an alternateSELECTEDVALUE ( 'Date'[Year], "All years" )
LOOKUPVALUEthe value in the row matching all search valuesLOOKUPVALUE ( Rates[Rate], Rates[Currency], "USD", Rates[Date], DATE ( 2026, 10, 1 ) )
EARLIERa column's value in the outer row contextFILTER ( Sales, Sales[Date] <= EARLIER ( Sales[Date] ) )
EARLIESTthe value in the outermost row contextEARLIEST ( Sales[Date] )
Reading the context and other rows

In depth: SELECTEDVALUE and HASONEVALUE, LOOKUPVALUE, EARLIER and EARLIEST.

Which window functions are filter functions?

They return rows relative to the current one, in a table ordered and partitioned as you say:

FunctionReturnsExample
OFFSETthe row a given distance awayCALCULATE ( [Revenue], OFFSET ( -1, ALLSELECTED ( 'Date'[Year Month] ), ORDERBY ( 'Date'[Year Month] ) ) )
INDEXthe row at an absolute positionCALCULATE ( [Revenue], INDEX ( 1, ALLSELECTED ( 'Date'[Year Month] ), ORDERBY ( 'Date'[Year Month] ) ) )
WINDOWa range of rows, absolute or relativeCALCULATE ( [Revenue], WINDOW ( -2, REL, 0, REL, ALLSELECTED ( 'Date'[Year Month] ), ORDERBY ( 'Date'[Year Month] ) ) )
RANKthe rank of the current row by columns, with ties (DENSE or SKIP)RANK ( DENSE, ALLSELECTED ( 'Product'[List Price] ), ORDERBY ( 'Product'[List Price], DESC ) )
ROWNUMBERa unique number for the current rowROWNUMBER ( ALLSELECTED ( Customer[Customer] ), ORDERBY ( Customer[Customer] ) )
ORDERBYthe sort of the window's rowsORDERBY ( 'Date'[Year Month], ASC )
PARTITIONBYthe groups the window restarts inPARTITIONBY ( 'Date'[Year] )
MATCHBYthe columns that identify the current rowMATCHBY ( 'Date'[Year Month] )
Window functions

Microsoft notes that RANK does not relate to RANKX as SUM to SUMX: RANK orders by columns of the relation, while RANKX ranks by any expression, such as a measure. In depth: OFFSET, WINDOW, INDEX, RANK and ROWNUMBER.

Which are visual calculation functions?

RUNNINGSUM, MOVINGAVERAGE, PREVIOUS, NEXT, FIRST, LAST, RANGE, LOOKUP and LOOKUPWITHTOTALS work in visual calculations, on the visual's own rows and columns:

Running sum = RUNNINGSUM ( [Sales Amount] )
Versus previous = [Sales Amount] - PREVIOUS ( [Sales Amount] )
Bikes value = LOOKUP ( SUM ( [Sales Amount] ), [Category], "Bikes" )

All of them: visual calculation functions.

What goes wrong?

  • REMOVEFILTERS where a table is needed. It only removes filters; to iterate or count all rows, use ALL.
  • ALLCROSSFILTERED as a table. Like REMOVEFILTERS, it cannot return a table.
  • Window functions without a stable order. Ties in ORDERBY make OFFSET and INDEX ambiguous; order by a unique column or add one.
  • DirectQuery limits. Several of these functions are not supported in calculated columns or RLS rules in DirectQuery mode; check each function's page.

Where can you check this?

Where do you start?

Learn CALCULATE, FILTER, REMOVEFILTERS and SELECTEDVALUE first: they cover most measures. Then OFFSET for comparisons with the previous row.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.