07.6NOT
At times you will want the opposite of a condition, for example the revenue of all cities except New York and Chicago, to follow what sells outside the US. NOT reverses a condition. It is mostly useful where no operator says the opposite, as with IN.
07.6.1Reversing a condition
NOT turns TRUE into FALSE, and FALSE into TRUE.
It expects a single argument, a condition.
Outside New York = NOT( Customers[City] = "New York" )| Customer ID | Name | City | Outside New York |
|---|---|---|---|
| C001 | Orvane | New York | False |
| C002 | Kumora | New York | False |
| C003 | Talvio | New York | False |
| C004 | Ribelia | Chicago | True |
| C005 | Movara | Chicago | True |
| C006 | Northel | Toronto | True |
| C007 | Sam Lee | Toronto | True |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
This condition answers TRUE for the customers who are not in New York, those in Chicago and in Toronto.
07.6.2NOT or <>?
For a single value, the <> operator already says “different from.” These two conditions answer the same way:
In general, prefer <>, which is shorter to read.
NOT can be written without parentheses, as in NOT Customers[City] = "New York". The parentheses make the condition clearer.
07.6.3NOT with IN
In Excel
| Excel | NOT |
|---|---|
| Match |
DAX has no operator for “is none of these values.” NOT, placed in front of IN, plays that role:
“I want the sum of the sale amounts, keeping only the customers who are neither in New York nor in Chicago.”
CALCULATE keeps the sales of the customers who are neither in New York nor in Chicago, that is the three sales of Toronto. SUM adds up their amounts, that is 300,000.
Practice
Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.
Direct useMeasureDifficulty
A library stores its loans in the “Loans” table, with the shelf of each book. Write the “Loans Excluding Children” measure, shown in a card, the number of loans whose shelf is neither “Children” nor “Comics.”
Loans Book Shelf Dune Novel Tintin Comics Emma Novel Matilda Children Cosmos Science Which formula should you write for “Loans Excluding Children”?
Combined useMeasureDifficulty
A carrier records in the “Parcels” table the delivery city and the weight of each parcel, in kilos. It wants to know what share of the total weight goes somewhere other than Lyon and Lille. Write the “Share Excluding Lyon and Lille” measure, shown in a card.
Parcels City Weight Lyon 12 Nantes 5 Lille 8 Brest 3
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
Placed on its own, without any filter, what does the measure CALCULATE( SUM( Sales[Amount] ), NOT( Products[Category] IN { "Sedan", "SUV" } ) ) return?
Question 2
You add to the Customers table a calculated column with the condition NOT( Customers[City] = "New York" ) || NOT( Customers[City] = "Chicago" ). How many customers answer TRUE?
Question 3
The Customers table holds only three cities, New York, Chicago and Toronto. Which condition keeps the customers in New York and in Chicago?
- NOT( <condition> ) reverses the answer of a condition.
- For a single value, the <> operator is enough.
- To set aside several values of the same column, write NOT in front of IN, as in NOT( Customers[City] IN { "New York", "Chicago" } ).