Stop 08 · Filter Context & CALCULATETopics · 4/9

FILTER Function

Part of the Power BI Roadmap

In short

Simple filters like City = "Pune" go straight into CALCULATE. But "customers who spent over ₹50,000" needs a measure in the condition, and that's where FILTER comes in.

FILTER returns a table of rows that meet a condition and is often used inside CALCULATE for complex conditions. Simple column filters are usually faster without it.

The jaadu shakes a large round sieve over a steel bowl, letting good rice grains fall through while small stones stay behind.

Think of it like this

A sieve for rice

You pour rice through a sieve and only grains of the right size pass through. FILTER is a sieve for table rows: it checks each row against your condition and returns only the rows that pass. CALCULATE then uses those rows as a filter.

Watch it happen

FILTER ( VALUES ( Customer[CustomerKey] ), [Total Sales] > 50000 )

Asha 72k
0
Ravi 18k
1
Meera 51k
2
Imran 9k
3
Kavya 64k
4

1/4VALUES gives the customers in the current filter context.

The big ideas

What you need to know

FILTER ( table, condition )

Iterates the table and returns the rows where the condition is true. It's a table function.

Needed for measures

Conditions that use a measure must go through FILTER. A plain boolean argument can't.

Filter columns, not tables

FILTER ( VALUES ( Customer[CustomerKey] ), ... ) is far lighter than FILTER ( Sales, ... ) over millions of rows.

Simple filters don't need it

CALCULATE ( [Total Sales], Store[City] = "Pune" ) is clearer and usually faster than wrapping it in FILTER.

See it in code

Walk through the code

dax
1Sales from Big Customers =2CALCULATE (3    [Total Sales],4    FILTER (5        VALUES ( Customer[CustomerKey] ),6        [Total Sales] > 500007    )8)9 10Big Customers =11COUNTROWS (12    FILTER ( VALUES ( Customer[CustomerKey] ), [Total Sales] > 50000 )13)

1/4Iterate only the customers visible in the current cell, not the whole Sales table.

Sales from customers whose own total is above ₹50,000, and how many such customers there are.

Save yourself the pain

Common mistakes

Oops

Writing FILTER ( Sales, RELATED ( Store[City] ) = "Pune" ) inside CALCULATE.

Do this instead

Use Store[City] = "Pune" directly. Iterating the whole fact table is slower and can keep filters you meant to replace.

Oops

Using FILTER ( ALL ( Customer ), ... ) when you wanted to respect the slicers.

Do this instead

ALL ignores current filters. Use VALUES to iterate only the customers currently visible.

Your mission

Find big spenders

~20 min

Quick check

When must you use FILTER instead of a simple boolean argument in CALCULATE?

Go deeper

  1. 1Count customers whose total sales exceed a threshold using FILTER over VALUES.
  2. 2Compare CALCULATE with a simple predicate vs with FILTER over the whole table.
  3. 3Filter a column, not a whole fact table, when you can.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge