The FILTER function in DAX returns a table that is a filtered copy of another table. You give it a table expression and a boolean condition, and it returns only the rows where that condition is true. It does not change the original table, and it does not return a single value — it always returns a table. That table can then be used by other functions such as CALCULATE, SUMX, COUNTROWS, or as the source for a measure that iterates over rows. FILTER is one of the most flexible tools in DAX, but it is also one of the most misused, because it can be slower and more complex than simpler alternatives like KEEPFILTERS or direct filter arguments in CALCULATE.
What You'll Need
- A data model in Power BI, Excel Power Pivot, Analysis Services, or any tool that supports DAX.
- At least one table loaded into the model, ideally with a date column and a numeric column for testing.
- A basic understanding of measures vs. calculated columns, and of row context vs. filter context.
- A place to write DAX: the formula bar in Power BI Desktop, the DAX editor in Excel, or a tool like DAX Studio.
Step-by-Step
- Understand the syntax. FILTER takes two arguments:
FILTER(<table>, <condition>). The first is a table expression, such asSalesorALL(Sales). The second is a boolean expression evaluated for each row of that table. Rows where the condition is TRUE are kept; rows where it is FALSE or BLANK are removed. - Start with a simple measure. Open your model and create a new measure. For example:
HighValueSales = SUMX( FILTER( Sales, Sales[Amount] > 1000 ), Sales[Amount] ). This sums the Amount column only for rows where Amount is greater than 1000. Note that FILTER returns a table, and SUMX iterates over it. - Check the result. Add the measure to a visual, such as a card or a table by product. Confirm that the number matches what you expect. If it does not, the condition may be referencing the wrong column or the wrong table.
- Use FILTER inside CALCULATE. A common pattern is
CALCULATE( SUM( Sales[Amount] ), FILTER( Sales, Sales[Amount] > 1000 ) ). Here FILTER produces a table of rows that pass the condition, and CALCULATE uses that table as a filter. This is equivalent to the previous example but uses CALCULATE instead of SUMX. - Filter on multiple conditions. Combine conditions with
&&(AND) or||(OR). For example:FILTER( Sales, Sales[Amount] > 1000 && Sales[Region] = "North" ). Parentheses help keep the logic clear. - Use FILTER with ALL to ignore existing filters.
FILTER( ALL( Sales ), Sales[Amount] > 1000 )removes any filters already applied to the Sales table before applying the new condition. This is useful when you want a measure to consider all rows regardless of slicers. - Use FILTER with RELATED for lookup columns. If the column you want to filter on lives in a related table, use
RELATED. For example:FILTER( Sales, RELATED( Product[Category] ) = "Bikes" ). This works when there is a relationship from Sales to Product. - Test performance. FILTER iterates over every row of the table you give it, so filtering a large fact table can be slow. If the condition is a simple column comparison, prefer CALCULATE with a direct filter argument, like
CALCULATE( SUM( Sales[Amount] ), Sales[Amount] > 1000 ), which can be optimised better by the engine. - Use FILTER only when necessary. Reserve FILTER for cases where the condition is complex, references multiple columns, or needs to be evaluated row by row. For simple equality or range filters, direct filter arguments in CALCULATE are usually faster and easier to read.
Common Mistakes
- Using FILTER where a simple filter works. Writing
CALCULATE( SUM( Sales[Amount] ), FILTER( Sales, Sales[Region] = "North" ) )is slower thanCALCULATE( SUM( Sales[Amount] ), Sales[Region] = "North" ). The second form lets the engine use indexes and optimisations. - Forgetting that FILTER returns a table. You cannot use FILTER directly in a scalar context, such as a card visual without an aggregator. You need SUMX, COUNTROWS, or another table-consuming function.
- Filtering the wrong table. If you filter the fact table but the column you need is in a dimension, use RELATED or filter the dimension table instead. Filtering the wrong side of a relationship can produce unexpected results.
- Ignoring context transition. Inside CALCULATE, FILTER is evaluated in the filter context of the CALCULATE. If you are used to row context, this can cause confusion. Use variables to debug intermediate tables.
- Using FILTER with ALL on large tables.
FILTER( ALL( BigTable ), ... )materialises the entire table before filtering, which can be very slow. Consider usingALLSELECTEDor a more targeted approach.
Tips
- Use variables to store the filtered table:
VAR FilteredSales = FILTER( Sales, Sales[Amount] > 1000 ) RETURN SUMX( FilteredSales, Sales[Amount] ). This makes the code easier to read and debug. - When filtering on a date range, use rather than filtering the fact table directly, to leverage the date table.
- Remember that FILTER does not remove existing filters unless you use ALL or REMOVEFILTERS inside it. If you want to keep existing filters and add a new one, use KEEPFILTERS around the FILTER result.
- For debugging, return the filtered table as a calculated table (using “New table” in Power BI) to see exactly which rows pass the condition.
- Prefer
COUNTROWS( FILTER( ... ) )overCOUNTROWS( CALCULATETABLE( ... ) )when you need to count rows that meet a complex condition, but check performance.
Troubleshooting
- The measure returns blank or zero. Check that the condition is actually true for some rows. Use a calculated table to inspect the filtered rows. Also check that the column names are correct and that you are not filtering on a column that has been renamed.
- The result is higher than expected. You may be ignoring existing filters unintentionally. If you used ALL, the measure will ignore slicers. Remove ALL or use KEEPFILTERS to respect the current filter context.
- Performance is slow. FILTER over a large table is a common cause. Try to replace it with a direct filter argument in CALCULATE. If you must use FILTER, filter a smaller table (like a dimension) or use a variable to reduce the number of rows.
- You get an error about a single value. This happens when you use FILTER in a context that expects a scalar. Wrap it in an aggregator like SUMX or COUNTROWS.
- RELATED does not work. Ensure there is an active relationship between the tables and that you are filtering the table on the “many” side. If the relationship is inactive, use USERELATIONSHIP.
Frequently Asked Questions
What is the difference between FILTER and CALCULATETABLE?
FILTER returns a table with rows that meet a condition, but it does not change the filter context. CALCULATETABLE modifies the filter context before evaluating the table expression. They are often used together: CALCULATETABLE( FILTER( ... ), ... ).
Can FILTER be used in a calculated column?
Yes, but it is rarely a good idea. In a calculated column, FILTER evaluates in row context and can be very slow because it may scan the entire table for each row. Use it only for small tables or when no alternative exists.
Does FILTER remove duplicates?
No. FILTER only removes rows that do not meet the condition. It does not remove duplicate rows. To remove duplicates, use DISTINCT or VALUES on the result.
Why does FILTER sometimes return all rows?
If the condition is always TRUE (for example, a column compared to itself), FILTER returns all rows. Also, if the condition evaluates to BLANK for all rows, FILTER returns no rows. Check the logic of your condition.
Can I use FILTER with a measure?
No. FILTER expects a table as its first argument. Measures return scalar values, not tables. You can use FILTER with a table or a table expression like ALL( Table ).
Is FILTER case-sensitive?
DAX string comparisons are case-insensitive by default. However, the underlying data source may be case-sensitive. Use EXACT if you need a case-sensitive comparison, but note that EXACT is not commonly used with FILTER.