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.

NOT( <condition> )

It expects a single argument, a condition.

NOT( Customers[City] = "New York" )
Outside New York = NOT( Customers[City] = "New York" )
Table Customers
Customer IDNameCityOutside New York
C001OrvaneNew YorkFalse
C002KumoraNew YorkFalse
C003TalvioNew YorkFalse
C004RibeliaChicagoTrue
C005MovaraChicagoTrue
C006NorthelTorontoTrue
C007Sam LeeTorontoTrue
Table: Customers (7 rows)

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:

NOT( Customers[City] = "New York" )
Customers[City] <> "New York"

In general, prefer <>, which is shorter to read.

Tip

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
ExcelNOT
Match

DAX has no operator for “is none of these values.” NOT, placed in front of IN, plays that role:

Revenue Outside the US = CALCULATE( SUM( Sales[Amount] ), NOT( Customers[City] IN { "New York", "Chicago" } ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
In plain words

“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.

  1. 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
    BookShelf
    DuneNovel
    TintinComics
    EmmaNovel
    MatildaChildren
    CosmosScience

    Which formula should you write for “Loans Excluding Children”?

  2. 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
    CityWeight
    Lyon12
    Nantes5
    Lille8
    Brest3

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?

Key takeaways
  • 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" } ).