FILTER Function
FILTER Function
I. Table
II. Condition
Dummy Table =
FILTER (
Sales, -- This is the Table
Sales[Sales Amount] >= 20 -- A condition for each row, returns
TRUE / FALSE output
)
2
Input 1 Table – The Sales table is filtered
Input 2 Condition – Check if each row is >= $20. Note
the condition will return either a TRUE or FALSE for
each row of the Sales Table.
Output Table – You’ll get a table with rows that
matched the condition.
Let’s solve this Question – Get a table of dates where the sales
amount is >= $50000. Consider this DAX for creating a Table.
Dummy Table 2 =
FILTER (VALUES (Sales [Order Date]), -- VALUES creates a
single columnar table with unique dates.
[Total Sales] >= 50000 -- For each date (row) check if Total
Sales >= 50000
)
3
Input 1 Table – The VALUES Function creates a one
columnar table with unique Dates.
Input 2 Condition – Check if Total Sales Value for each
date is >= $50,000. Again, the condition will return
either a TRUE or FALSE for each row of the Virtual
Table.
Output Table – You’ll again get a table with rows that
matched the condition.
The output contains 133 rows, i.e. there were 133 days when the
sales were more than $50,000.
Sales >50k=
FILTER (
VALUES (Sales [Order Date]), -- The VALUES function creates
a Virtual Table.
[Total Sales] >= 50000 -- This condition is tested for each row
of the Virtual Table
)
4
The Problem – If you drag this measure to a visual / a Pivot
Table, this will throw an error.
Sales >50K =
CALCULATE (
[Total Sales],
FILTER (
VALUES (‘Calendar'[Date]),
[Total Sales] >= 50000
)
)
5
The CALCULATE function outside aggregates (sums) the sales
value for the rows returned by the FILTER Function.
6
END