FILTER
The rows of a table for which a condition is TRUE.
Group: Filter. Compatible with DAX.
Syntax
FILTER ( <table>, <filter> )
| Parameter | Type | Description |
|---|---|---|
table | Table | The rows to go through: a table of the model or any table expression. |
filter | Boolean evaluated for each row | The condition worked out for each row; the rows where it is TRUE stay in the result. |
Returns
Table. The rows of the table for which the condition is TRUE, with all the table's columns.
Remarks
- The condition sees each row in turn. A blank result counts as FALSE, and in a comparison a blank counts as zero:
[Liters] < 60keeps a row whose liters are blank. - A measure in the condition is worked out with the row as its filter:
FILTER ( VALUES ( Places[District] ), [Liters sold] > 150000 )gives the districts that sold more. - The table comes in the current filter context:
FILTER ( Products, ... )sees only the products already in view,FILTER ( ALL ( Products[Category] ), ... )all categories. - As a filter of
CALCULATE, a FILTER over the column or two that matter is clearer, and faster, than one over a whole large table.
Examples
Order lines over 60 liters
EVALUATE
VAR Orders =
DATATABLE (
"Product", STRING, "Liters", INTEGER,
{ { "Pils", 120 }, { "IPA", 80 }, { "Cider", BLANK () }, { "Stout", 45 } }
)
RETURN
FILTER ( Orders, [Liters] > 60 )
| Product | Liters |
|---|---|
| Pils | 120 |
| IPA | 80 |
A blank counts as zero
The Cider line has no liters; as zero it is less than 60, so the line stays.
EVALUATE
VAR Orders =
DATATABLE (
"Product", STRING, "Liters", INTEGER,
{ { "Pils", 120 }, { "IPA", 80 }, { "Cider", BLANK () }, { "Stout", 45 } }
)
RETURN
FILTER ( Orders, [Liters] < 60 )
| Product | Liters |
|---|---|
| Cider | (blank) |
| Stout | 45 |
Districts by a measure
EVALUATE
FILTER ( VALUES ( Places[District] ), [Liters sold] > 150000 )
ORDER BY Places[District]
| Places[District] |
|---|
| Frogner |
| Majorstuen |
| St. Hanshaugen |
Related functions
CALCULATE, CALCULATETABLE, ALL, VALUES, COUNTROWS, KEEPFILTERS.