Curious Minds

Clear answers to science and history questions

Dax Begins with Filter? The CALCULATE Rule

· 5 min read · Science

No, DAX does not begin with FILTER. DAX begins with a table expression or a scalar expression. When you write a measure, the expression after the equals sign is evaluated in a filter context. FILTER is a function that returns a table, and it is often used inside CALCULATE to modify that filter context. But FILTER is not the starting point of DAX syntax, and it is not required for most calculations.

The confusion is common because many DAX tutorials introduce FILTER early, especially when explaining CALCULATE. The phrase "Dax begins with filter" may come from a misreading of how CALCULATE works: CALCULATE evaluates an expression in a modified filter context, and one way to modify that context is to pass a FILTER table. That does not mean DAX begins with FILTER. It means FILTER is one of several tools for shaping context.

What DAX Actually Begins With

A DAX formula begins with the name of the measure or calculated column, followed by an equals sign, followed by an expression. The expression can be as simple as a number, a column reference, or an aggregate function. For example:

  • Total Sales = SUM(Sales[Amount]) begins with SUM, not FILTER.
  • Row Count = COUNTROWS(Sales) begins with COUNTROWS.
  • Profit = [Total Sales] - [Total Cost] begins with a measure reference.

In each case, the first token after the equals sign is the function or reference that produces the result. FILTER appears only when a table expression is needed, often as an argument to another function.

Where FILTER Fits in the DAX Language

FILTER is a table function. It takes a table and a boolean expression, and returns a table containing only the rows where the expression is true. Its syntax is:

FILTER(

, )

Because it returns a table, FILTER is typically used inside functions that accept a table argument, such as CALCULATE, CALCULATETABLE, SUMX, AVERAGEX, and others. For example:

Sales Large Orders = CALCULATE([Total Sales], FILTER(Sales, Sales[Amount] > 1000))

Here, CALCULATE begins the expression, and FILTER is an argument that modifies the filter context. The formula does not begin with FILTER; it begins with CALCULATE.

How CALCULATE and FILTER Work Together

CALCULATE is the primary function for changing filter context in DAX. It evaluates an expression in a context modified by the filters you specify. Those filters can be simple column predicates, table expressions, or a combination. FILTER is one way to create a table expression for CALCULATE, but it is not the only way.

Simple predicates are often more efficient than FILTER. For example, CALCULATE([Total Sales], Sales[Amount] > 1000) is a filter argument that does not use FILTER. It is shorter and usually faster because the engine can optimize it directly. FILTER becomes necessary when the condition must be evaluated row by row against a table, especially when the condition references multiple columns or measures.

  • Use a simple predicate when filtering a single column with a constant or a measure.
  • Use FILTER when the condition involves multiple columns, or when you need to iterate over a table and evaluate an expression per row.
  • Use KEEPFILTERS to preserve existing filters when adding a new one.
  • Use REMOVEFILTERS or ALL to clear filters before applying new ones.

Common Misconceptions About DAX and FILTER

One misconception is that every DAX formula must include FILTER to work correctly. That is false. Many measures use only aggregation functions and rely on the existing filter context from the report visuals. Another misconception is that FILTER is always the best way to filter. In practice, simple predicates are often better for performance. A third misconception is that FILTER can be used anywhere. FILTER returns a table, so it cannot be used where a scalar value is expected unless wrapped in an aggregation function.

It is also worth noting that FILTER is not a filter context modifier by itself. It returns a table, and that table must be passed to a function like CALCULATE to affect the filter context. Writing FILTER(Sales, Sales[Amount] > 1000) alone in a measure would return a table, which is not a valid scalar result for a measure.

When to Use FILTER vs. Simple Predicates

Choosing between FILTER and a simple predicate depends on the condition and the data model. Here are practical guidelines:

  • If the condition compares a single column to a constant, use a simple predicate: CALCULATE([Measure], Table[Column] = "Value").
  • If the condition compares a column to a measure, a simple predicate may still work, but FILTER is often used when the measure must be evaluated in the row context of the table.
  • If the condition involves multiple columns, use FILTER: FILTER(Table, Table[Col1] > Table[Col2]).
  • If you need to filter a table based on an aggregate of another table, FILTER is usually required.

Performance testing in your own model is the best way to decide. In general, simple predicates are preferred when they are semantically equivalent.

Frequently Asked Questions

Does DAX always start with FILTER?

No. DAX formulas start with the expression that produces the result, which can be an aggregation, a measure reference, a constant, or another function. FILTER is just one of many functions and is used only when a filtered table is needed.

Is FILTER required for CALCULATE?

No. CALCULATE can accept simple column predicates, table expressions, or no filter arguments at all. FILTER is optional and is used when the filter condition requires row-by-row evaluation.

Can I use FILTER without CALCULATE?

Yes, FILTER can be used inside other functions that accept a table, such as SUMX, AVERAGEX, or COUNTROWS. However, FILTER alone returns a table and cannot be the final result of a measure unless aggregated.

Why do some DAX examples begin with FILTER?

Some examples show FILTER as the first argument to an iterator function, such as SUMX(FILTER(...), ...). In those cases, the formula begins with SUMX, not FILTER. The FILTER is nested inside. A formula that literally begins with FILTER would return a table, which is only valid in a calculated table or as an argument to another function.

What is the difference between FILTER and KEEPFILTERS?

FILTER returns a table of rows that meet a condition. KEEPFILTERS is a CALCULATE modifier that preserves existing filters on a column while adding a new filter. They serve different purposes and are not interchangeable.

Is FILTER bad for performance?

FILTER can be slower than simple predicates because it may require iterating over a table. However, it is necessary for certain conditions. Use simple predicates when possible, and test performance in your model.

In this article
  1. What DAX Actually Begins With
  2. Where FILTER Fits in the DAX Language
  3. How CALCULATE and FILTER Work Together
  4. Common Misconceptions About DAX and FILTER
  5. When to Use FILTER vs. Simple Predicates
  6. Frequently Asked Questions