DAX Comparison Operators: Equal To, Not Equal To, Greater Than and Less Than
In this article, we will learn how to use comparison operators in DAX to filter tables and identify records that meet specific conditions. We will explore Equal To, Not Equal To, Greater Than or Equal To, and Less Than operators using practical examples with the Customer and Sales tables.
These operators are essential for filtering data based on text values, numeric values, and calculated expressions. By the end of this article, you will understand how to write DAX queries that return only the records you need.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Are Comparison Operators in DAX?
Comparison operators are used to compare values and return a Boolean result: TRUE or FALSE. They are commonly used inside functions such as FILTER to determine which rows should be included in the result.
| Operator | Meaning | Example |
|---|---|---|
| == | Equal To | Sales[Sales Amount] == 5000 |
| <> | Not Equal To | Sales[Sales Amount] <> 5000 |
| >= | Greater Than or Equal To | Sales[Sales Amount] >= 5000 |
| < | Less Than | Sales[Sales Amount] < 5000 |
Comparison operators help us define the conditions that determine which rows are returned by a DAX query.
Understanding the FILTER Function
Before exploring the comparison operators, let us understand the FILTER function used in these examples.
FILTER(
<Table>,
<Filter Expression>
)
Step 1: Table
Specifies the table from which we want to retrieve rows.
Step 2: Filter Expression
Specifies the condition that each row must satisfy.
Step 3: Return Result
FILTER returns a new table containing only the rows for which the condition evaluates to TRUE.
FILTER does not modify the original table. It returns a filtered table expression that can be used in a DAX query.
1. Equal To Operator (==)
The Equal To operator is used when we want to retrieve rows where a column value exactly matches a specified value.
Query
// 1. Equal To
EVALUATE
Customer
EVALUATE
FILTER(
Customer,
Customer[Country-Region] == "Australia"
)
Step-by-step explanation
Step 1: EVALUATE Customer
The first query returns the complete Customer table. This allows us to view the original data before applying any filter.
Step 2: FILTER(Customer, …)
The second query uses FILTER to create a new table from the Customer table.
Step 3: Customer[Country-Region] == “Australia”
This is the filter condition. DAX checks whether the value in the Country-Region column is equal to “Australia”.
Step 4: Return matching rows
Only the customers whose country-region is Australia are included in the result.
What will you get?
The result will contain only the rows where Country-Region is Australia.
| Customer | Country-Region |
|---|---|
| Example Customer 1 | Australia |
| Example Customer 2 | Australia |
The example above is for illustration. Your actual result will contain the matching customers available in your Customer table.
The == operator returns rows where the specified column value matches the condition exactly.
2. Not Equal To Operator (<>)
The Not Equal To operator is used when we want to exclude rows that match a specific value.
Query
// 2. Not Equal To
EVALUATE
FILTER(
Customer,
Customer[State-Province] <> "California"
)
Step-by-step explanation
Step 1: FILTER(Customer, …)
The query starts with the Customer table as the source.
Step 2: Customer[State-Province] <> “California”
DAX checks whether the value in the State-Province column is not equal to “California”.
Step 3: Return matching rows
Rows where the state-province is not California are returned.
What will you get?
The result will contain customers whose State-Province is different from California.
| Customer | State-Province |
|---|---|
| Example Customer 1 | New York |
| Example Customer 2 | Texas |
The example above is for illustration. Your actual result will contain the matching customers available in your Customer table.
The <> operator is useful when you want to exclude a specific value from your result.
3. Greater Than or Equal To Operator (>=)
The Greater Than or Equal To operator is used when we want to retrieve rows where a numeric value is greater than or equal to a specified number.
Query
// 3. Greater Than or Equal To
EVALUATE
FILTER(
Sales,
Sales[Sales Amount] >= 5000
)
Step-by-step explanation
Step 1: FILTER(Sales, …)
The query uses the Sales table as the source.
Step 2: Sales[Sales Amount] >= 5000
DAX checks whether the Sales Amount is greater than or equal to 5000.
Step 3: Return matching rows
Rows with sales amounts of 5000 or more are returned.
What will you get?
The result will contain sales transactions where Sales Amount is at least 5000.
| Sales Amount | Result |
|---|---|
| 5000 | Included |
| 7500 | Included |
| 4500 | Excluded |
The example above is for illustration. Your actual result will contain the matching sales transactions available in your Sales table.
The >= operator includes the specified value as well as all values greater than it.
4. Less Than Operator (<)
The Less Than operator is used when we want to retrieve rows where a value is smaller than a specified number.
Query
// 4. Less Than
EVALUATE
FILTER(
Sales,
Sales[Sales Amount] - Sales[Total Product Cost] < 0
)
Step-by-step explanation
Step 1: FILTER(Sales, …)
The query uses the Sales table as the source.
Step 2: Sales[Sales Amount] – Sales[Total Product Cost]
DAX calculates the difference between Sales Amount and Total Product Cost for each row.
Step 3: < 0
The result is compared with 0. The condition is TRUE only when the difference is negative.
Step 4: Return matching rows
Only rows where the calculated difference is less than zero are returned.
Understanding the calculation
Sales Amount - Total Product Cost < 0
| Sales Amount | Total Product Cost | Difference | Result |
|---|---|---|---|
| 5000 | 6000 | -1000 | Included |
| 7000 | 7000 | 0 | Excluded |
| 8000 | 5000 | 3000 | Excluded |
The example above is for illustration. Your actual result will contain the matching sales transactions available in your Sales table.
This query identifies rows where Sales Amount is less than Total Product Cost, meaning the calculated difference is negative.
Understanding the Difference Between the Operators
| Operator | Condition | Example | Meaning |
|---|---|---|---|
| == | Equal To | Sales Amount == 5000 | Returns exactly 5000 |
| <> | Not Equal To | State-Province <> “California” | Excludes California |
| >= | Greater Than or Equal To | Sales Amount >= 5000 | Returns 5000 and above |
| < | Less Than | Difference < 0 | Returns negative values |
Important Notes
1. Comparison operators return TRUE or FALSE
Every comparison evaluates to a Boolean result. For example, 5000 >= 5000 returns TRUE, while 4500 >= 5000 returns FALSE.
2. Text values must be enclosed in double quotes
When comparing text values, use double quotes around the text.
Customer[Country-Region] == "Australia"
3. Numeric values do not require quotes
Numeric values are written directly without quotation marks.
Sales[Sales Amount] >= 5000
4. Comparison operators can be used with calculated expressions
In the fourth example, we are not comparing a single column directly. Instead, we calculate the difference between two columns and then compare that result with zero.
Sales[Sales Amount] - Sales[Total Product Cost] < 0
5. FILTER returns a table
Since FILTER returns a table expression, it can be used directly with EVALUATE to display the matching rows.
📝 Practice Exercise
Try writing the following DAX queries using the Customer and Sales tables.
- Retrieve customers whose Country-Region is “United States”.
- Retrieve customers whose State-Province is not “California”.
- Retrieve sales transactions where Sales Amount is greater than or equal to 10000.
- Retrieve sales transactions where Sales Amount is less than Total Product Cost.
Example Practice Query
EVALUATE
FILTER(
Sales,
Sales[Sales Amount] >= 10000
)
Modify the numeric value and comparison operator to practice different filtering conditions.
Conclusion
In this article, we learned how to use comparison operators in DAX to filter tables and retrieve records based on specific conditions.
- == checks whether two values are equal.
- <> checks whether two values are different.
- >= returns values greater than or equal to a specified number.
- < returns values less than a specified number.
- Comparison operators can be used with text, numeric values, and calculated expressions.
- FILTER uses these conditions to return only the matching rows.
These operators are fundamental for writing DAX queries and are widely used in data analysis, reporting, and business intelligence.
Next: We can learn how to combine multiple conditions using logical operators such as && and ||.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist