0% found this document useful (0 votes)
12 views7 pages

FILTER Function

The DAX FILTER function is used to filter a table based on a specified condition, returning only the rows that meet the criteria. It can be applied to both physical and virtual tables, allowing for dynamic data manipulation. Additionally, when used in measures, the FILTER function must be combined with aggregation functions like CALCULATE to produce a scalar output.

Uploaded by

sumedtaremis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

FILTER Function

The DAX FILTER function is used to filter a table based on a specified condition, returning only the rows that meet the criteria. It can be applied to both physical and virtual tables, allowing for dynamic data manipulation. Additionally, when used in measures, the FILTER function must be combined with aggregation functions like CALCULATE to produce a scalar output.

Uploaded by

sumedtaremis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

FILTER Function

DAX FILTER Function Syntax


This function accepts two arguments

I. Table
II. Condition

1. The first argument, i.e., Table, accepts a physical or a


virtual table to Filter.
 A physical table can be seen in the data model.
 A virtual table is the one created on the fly.
2. The second argument, i.e., Condition accepts a logical test
that is performed in each row of the table.
 All rows that satisfy the condition, i.e. return TRUE are
kept while other rows are removed.
 Keep in mind the condition must return a True or False
output else it stands invalid.
“Important – The output of the FILTER function is a table
containing the rows that satisfied the condition.”

DAX FILTER Function in Action


Let's run the FILTER Function on this data model with Sales and
a standard Calendar Table linked with a one-to-many
relationship.

Because the FILTER Function returns a Table, let’s create a


Table. Go to Table Tools >> New Table.

Let’s create a simple table with a condition on the Sales Amount


column >= $20. Consider the following DAX Code.

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.

FILTER Function used on a Virtual Table


Sales was a physical table present in the Data Model, let’s see if
we can apply the FILTER function to a table that doesn’t
physically exist i.e., a Virtual Table.

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.

FILTER Function used in a Measure


Question – Find the Total Sales Amount for High Selling Days. A
High Selling Day will have Sales >= $50,000. Let’s build on this
from the previous example. Consider a new measure with the
same DAX Code used earlier for creating a virtual table.

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.

The Reason – Since the FILTER Function delivers a table, a


table cannot be summarized as a single value / scalar output.

The Solution – We need to SUM the values of the table to get


this right. Consider the revised DAX Measure.

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.

The output obtained would be as follows

6
END

You might also like