Nesting Conditional & Logical Operators
This page shows how M’s logical operators work in custom columns and in filters, and how to combine them with if … then … else to build nested conditions.
The logical operators
Section titled “The logical operators”M has three logical operators, written in lower case:
and, which is true only when both tests are trueor, which is true when either test is truenot, which reverses a test
The first examples use a single column of numbers:

Using the operators in custom columns
Section titled “Using the operators in custom columns”Each operator can drive a custom column that returns TRUE or FALSE for every row. On the Add Column tab, choose Custom Column for each of these.
A column named AND, which tests for values between 90 and 350:
![The Custom Column dialog with the new column name AND and the formula [Data] > 90 and [Data] <350](/_astro/nested-operators-2.BKRUDw7J_Z8rQXp.webp)
A column named OR, which tests for values below 140 or above 350:
![The Custom Column dialog with the new column name OR and the formula [Data] < 140 or [Data] > 350](/_astro/nested-operators-3.CIc3NVJe_Z1Piz6w.webp)
A column named NOT, which tests for values that are not below 250:
![The Custom Column dialog with the new column name NOT and the formula not([Data] < 250)](/_astro/nested-operators-4.fUTRV2rp_21MEXE.webp)
The query now shows the result of each test against each value:

Using the operators in filters
Section titled “Using the operators in filters”The same logic is available when filtering. Open the filter menu on the Data column, choose a number filter, and switch the Filter Rows dialog to Advanced. Each clause added with Add Clause can be joined to the one before it with And or Or, which makes fairly complex filters possible without writing any M:

Nesting tests inside if-then-else
Section titled “Nesting tests inside if-then-else”Logical operators can also sit inside the test of an if expression, which takes this form:
if logical test then result if true else result if false
An if expression can itself be the result of another, which is what nesting means here.
The next example is a table of savings accounts:

The interest on each account is calculated with a custom column named Interest, whose formula nests one if inside the else of another and uses and in each test:

In this formula, a main account earns the full rate and any other account earns three-quarters of it. Both tenure branches give the same result, so here they show how the nesting is written rather than changing the answer. Giving one branch a different calculation would make tenure count.
The Interest column appears at the end of the table:
