FILTER in DAX: when to use it and when not

How the FILTER function works in DAX, iterating a table and keeping rows that meet a condition, using it inside CALCULATE, COUNTROWS and SUMX, why Boolean filters are faster for simple conditions, filtering on measures, and filtering columns instead of whole tables.

Short answer: FILTER ( table, condition ) goes through a table row by row and returns the rows where the condition is TRUE. It is an iterator, so the condition can use the row's columns and measures. Use it when a filter needs a measure ([Revenue] > 10000), compares columns of different tables, or must be built from a table variable. For simple conditions on one column, a Boolean filter in CALCULATE ('Product'[Color] = "Red") is shorter and usually faster. Filter a column (VALUES ( Customer[Customer] )), not a whole fact table.

FILTER is the most overused function in DAX. It is also the only way to say "customers whose revenue is over 10,000". The difference is in what you pass it.

How does FILTER work?

  1. 1
    TableVALUES ( Customer[Customer] ): Ana, Ben, Chen, Dana
  2. 2
    Each rowevaluate [Revenue] > 10000 for that customer
  3. 3
    ResultBen, Dana: a table that can filter or be counted
FILTER over the customers in the current filter context
Big Customers =
COUNTROWS ( FILTER ( VALUES ( Customer[Customer] ), [Revenue] > 10000 ) )

Revenue from Big Customers =
CALCULATE ( [Revenue], FILTER ( VALUES ( Customer[Customer] ), [Revenue] > 10000 ) )

Inside FILTER, [Revenue] is evaluated per customer through context transition.

When should you use a Boolean filter instead?

-- good: Boolean filter on one column
Red Revenue = CALCULATE ( [Revenue], 'Product'[Color] = "Red" )

-- same result, more work: FILTER over the whole Product table
Red Revenue Slow = CALCULATE ( [Revenue], FILTER ( 'Product', 'Product'[Color] = "Red" ) )

Microsoft's guidance "Avoid using FILTER as a filter argument" explains: the Boolean form is translated into an efficient filter on the column, while FILTER over a table returns a table of all its columns, which is slower and can keep filters on other columns of that table. There is also a difference in meaning: FILTER ( 'Product', ... ) iterates the products in the current filter context, so it combines with existing filters, while the Boolean filter replaces the filter on Color. To get the Boolean result with FILTER, write FILTER ( ALL ( 'Product'[Color] ), 'Product'[Color] = "Red" ).

Which conditions need FILTER?

-- 1 a measure in the condition
Profitable Products =
COUNTROWS ( FILTER ( VALUES ( 'Product'[Product] ), [Margin] > 0 ) )

-- 2 two columns of the same table compared
Orders Shipped Late =
CALCULATE (
    COUNTROWS ( Orders ),
    FILTER ( ALL ( Orders[Ship Date], Orders[Due Date] ), Orders[Ship Date] > Orders[Due Date] )
)

-- 3 a condition on a related table's column per row
Sales Under List Price =
COUNTROWS ( FILTER ( Sales, Sales[Unit Price] < RELATED ( 'Product'[List Price] ) ) )

-- 4 keep only rows of a summary
Months Above Target =
COUNTROWS (
    FILTER (
        VALUES ( 'Date'[Month] ),
        [Revenue] >= [Revenue Target]
    )
)

In example 2, filtering the two columns rather than the whole Orders table keeps the filter small.

How do you make FILTER fast?

  • Iterate the smallest table: a column of distinct values (VALUES, ALL ( column )), not the fact table.
  • Filter columns before measures: when a condition is on a column, apply it as a Boolean filter in CALCULATE and keep only the measure test inside FILTER.
  • Avoid FILTER inside FILTER on large tables; compute a table variable once.
  • Let CALCULATE filter first: CALCULATE ( COUNTROWS ( FILTER ( VALUES ( Customer[Customer] ), [Revenue] > 1000 ) ), 'Date'[Year] = 2026 ) narrows the customers before the loop.

What goes wrong?

  • FILTER ( Sales, ... ) everywhere. Scanning millions of rows with all columns; filter a column instead.
  • Different results than expected. FILTER ( 'Product', ... ) respects existing filters; a Boolean filter overrides them.
  • Measures in a Boolean filter. Not allowed; that is exactly where FILTER is needed.
  • FILTER returning many columns into CALCULATE. Extra columns become filters too; return only the columns you mean.

Where can you check this?

Where do you start?

Search your model for FILTER ( <fact table>, and replace each simple one with a Boolean filter or a FILTER over a single column. CALCULATE explains what happens to the filter after FILTER builds it.

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.