Returns a table that has been filtered.
The table to be filtered.
A boolean (True/False) expression that is to be evaluated for each row of the table.
A table containing only the filtered rows.
FILTER can filter rows from a table by using any expression valid in the row context.
Thanks to context transition, using a measure in the filter expression it is possible to filter a table based on a dynamic calculation involving other rows and/or tables.
» 1 related function
Filter the customers in Europe.
EVALUATE FILTER ( Customer, Customer[Continent] = "Europe" )
-- Being an iterator, FILTER creates a row context. If you need -- to access related tables, the RELATED function is needed. -- This makes the usage of CALCULATE preferred over FILTER, when -- possible DEFINE MEASURE Sales[Red Sales] = SUMX ( FILTER ( Sales, RELATED ( Product[Color] ) = "Red" ), Sales[Quantity] * Sales[Net Price] ) MEASURE Sales[Red Sales CALCULATE] = CALCULATE ( [Sales Amount], KEEPFILTERS ( Product[Color] = "Red" ) ) EVALUATE SUMMARIZECOLUMNS ( Product[Brand], "Sales", [Sales Amount], "Red Sales", [Red Sales], "Red Sales CALCULATE", [Red Sales CALCULATE] )
|Product[Brand]||Sales||Red Sales||Red Sales CALCULATE|
|Wide World Importers||1,901,956.66||41,435.95||41,435.95|
|The Phone Company||1,123,819.07||(Blank)||(Blank)|
FILTER is needed to create a filter based on a measure relying on context transition.
DEFINE MEASURE Sales[Sales Amount] = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ) MEASURE Sales[Sales in countries >3M] = CALCULATE ( [Sales Amount], FILTER ( ALL ( Customer[CountryRegion] ), [Sales Amount] > 3000000 ) ) EVALUATE SUMMARIZECOLUMNS ( 'Date'[Calendar Year], "Sales amount", [Sales Amount], "Sales in countries >3M", [Sales in countries >3M] )
|Date[Calendar Year]||Sales amount||Sales in countries >3M|
FILTER is needed to iterate the content of a variable.
-- AVERAGE Monthly Sales computes the average sales for the months -- with at least 10K sales DEFINE MEASURE Sales[Sales Amount] = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ) MEASURE Sales[AVERAGE Monthly Sales] = VAR MonthlySales = ADDCOLUMNS ( DISTINCT ( 'Date'[Calendar Year Month] ), "@MonthlySales", [Sales Amount] ) VAR FilteredSales = -- Iterator required to filter the @MonthlySales column FILTER ( MonthlySales, [@MonthlySales] > 10000 ) VAR Result = AVERAGEX ( FilteredSales, [@MonthlySales] ) RETURN Result EVALUATE SUMMARIZECOLUMNS ( 'Product'[Color], "AVERAGE Monthly Sales", [AVERAGE Monthly Sales] )
|Color||AVERAGE Monthly Sales|
Learn more about FILTER in the following articles:
Filtering Tables in DAX
This article describes a number of techniques available to filter tables in DAX, showing possible pitfalls that you can avoid once you know them, in particular using bidirectional filters. One of the hardest things to do, when learning DAX, is to get rid of common sense reasoning and learn to follow a new set of […] » Read more
Context Transition and Filters in CALCULATE
This article explains how the context transition interacts with the filter arguments of a CALCULATE function in DAX. This is important in order to avoid unexpected results with complex calculations made in filter arguments. » Read more
Filter Arguments in CALCULATE
A filter argument in CALCULATE is always an iterator. Finding the right granularity for it is important to control the result and the performance. This article describes the options available to create complex filters in DAX. » Read more
FILTER vs CALCULATETABLE: optimization using cardinality estimation
A common best practice is to use CALCULATETABLE instead of FILTER for performance reasons. This article explores the reasons why and explains when FILTER might be better than CALCULATETABLE. » Read more
From SQL to DAX: Filtering Data
The WHERE condition of an SQL statement has two counterparts in DAX: FILTER and CALCULATETABLE. In this article we explore the differences between them, providing a few best practices in their use. » Read more
Applying a measure filter in Power BI
This article describes how to use a measure to filter a Power BI visualization, and the different behaviors of a same filter between different visuals. » Read more
Other related functions are:
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://docs.microsoft.com/en-us/dax/filter-function-dax