๐งฎ Mathematical, Relational, and Logical Operators
Building Complex Expressions in Spreadsheets
Operators are symbols that specify the type of calculation to perform in a formula. Understanding the different types of operators and how they work together is essential for creating effective spreadsheet calculations and conditions.
๐ข Mathematical Operatorsโ
Mathematical operators perform basic arithmetic calculations on numbers.
โ Addition (+)โ
- Adds two numbers together
- Syntax:
=A1+B1
or=5+10
- Example:
=SUM(A1:A10)+B5
adds the sum of range A1:A10 to the value in B5 - Can also concatenate text strings (though & is preferred)
โ Subtraction (-)โ
- Subtracts the second number from the first
- Syntax:
=A1-B1
or=20-5
- Example:
=COUNT(A1:A10)-COUNT(B1:B10)
finds the difference between two counts - Can also be used as a negative sign:
=-A1
โ๏ธ Multiplication (*)โ
- Multiplies two numbers together
- Syntax:
=A1*B1
or=5*10
- Example:
=A1*0.15
calculates 15% of the value in A1 - Use parentheses to control order:
=(A1+B1)*C1
โ Division (/)โ
- Divides the first number by the second
- Syntax:
=A1/B1
or=20/4
- Example:
=SUM(A1:A10)/COUNT(A1:A10)
calculates the average manually - Returns #DIV/0! error if dividing by zero
๐ Exponentiation (^)โ
- Raises a number to a power
- Syntax:
=A1^B1
or=5^2
- Example:
=4^0.5 // Square root of 4
=10^3 // 10 cubed (1000)
๐ฏ Percentage (%)โ
- Converts a number to a percentage (divides by 100)
- Syntax:
=A1*10%
or=50%
- Example:
=A1*B1% // B1 percent of A1
=50% // Equals 0.5
๐ Relational Operatorsโ
Relational operators compare two values and return a logical value (TRUE or FALSE).
๐ฐ Equal To (=)โ
- Tests if two values are equal
- Syntax:
=A1=B1
or=A1="Text"
- Example:
=IF(A1=10,"Yes","No") // Returns "Yes" if A1 equals 10
- Case-insensitive for text comparisons in most spreadsheets
โ Not Equal To (<>)โ
- Tests if two values are not equal
- Syntax:
=A1<>B1
or=A1<>"Text"
- Example:
=COUNTIF(A1:A10,"<>0") // Counts non-zero values
๐ Greater Than (>)โ
- Tests if the first value is greater than the second
- Syntax:
=A1>B1
or=A1>10
- Example:
=IF(A1>B1,"Above","Below or Equal") // Compares two cells
๐ Less Than (<)โ
- Tests if the first value is less than the second
- Syntax:
=A1<B1
or=A1<10
- Example:
=COUNTIF(A1:A10,"<0") // Counts negative values
๐ Greater Than or Equal To (>=)โ
- Tests if the first value is greater than or equal to the second
- Syntax:
=A1>=B1
or=A1>=10
- Example:
=IF(A1>=70,"Pass","Fail") // Simple grading rule
๐ Less Than or Equal To (<=)โ
- Tests if the first value is less than or equal to the second
- Syntax:
=A1<=B1
or=A1<=10
- Example:
=SUMIF(A1:A10,"<=0",B1:B10) // Sums values in B where A is negative or zero
๐งฉ Logical Operatorsโ
Logical operators combine or modify logical values (TRUE/FALSE).
๐ ANDโ
- Returns TRUE if all conditions are true
- Syntax:
=AND(logical1, logical2, ...)
- Example:
=AND(A1>10, A1<20) // TRUE if A1 is between 10 and 20
=IF(AND(A1>=60, B1>=60), "Pass", "Fail") // Requires passing both subjects
๐ ORโ
- Returns TRUE if any condition is true
- Syntax:
=OR(logical1, logical2, ...)
- Example:
=OR(A1="Yes", B1="Yes") // TRUE if either cell contains "Yes"
=IF(OR(A1<0, A1>100), "Invalid", "Valid") // Checks if value is out of range
๐ NOTโ
- Reverses a logical value (TRUE becomes FALSE, FALSE becomes TRUE)
- Syntax:
=NOT(logical)
- Example:
=NOT(A1>10) // Same as A1<=10
=IF(NOT(ISBLANK(A1)), "Filled", "Empty") // Checks if cell is not empty
๐ข Operator Precedenceโ
When a formula contains multiple operators, they are evaluated in a specific order:
- ๐ Parentheses
()
- ๐ Exponentiation
^
- โ๏ธ Multiplication
*
and Division/
(from left to right) - โ Addition
+
and Subtraction-
(from left to right) - ๐ Relational operators
=
,<>
,<
,<=
,>
,>=
- ๐งฉ Logical operators: NOT, AND, OR
Examples of Precedenceโ
=5+2*3 // Equals 11 (multiplication before addition)
=(5+2)*3 // Equals 21 (parentheses override default precedence)
=5>2*3 // Equals FALSE (multiplication before comparison)
=NOT(A1>5 AND A1<10) // Equals NOT(A1>5) OR NOT(A1<10) by De Morgan's Law
๐งช Combining Operators in Complex Formulasโ
๐ Nested Conditionsโ
- Use parentheses to group conditions
- Example:
=IF(AND(A1>=60, OR(B1>=70, C1>=80)), "Pass", "Fail")
- This checks if A1 is at least 60 AND either B1 is at least 70 OR C1 is at least 80
๐งฎ Mathematical and Logical Combinationsโ
- Example:
=IF((A1+B1)/2>60, "Pass", "Fail")
- This calculates the average of A1 and B1, then compares it to 60
๐ Text and Numeric Operationsโ
- Example:
=IF(A1>100, "High: " & A1, "Normal: " & A1)
- This combines text with the value from A1 based on a condition
โ Best Practicesโ
- Use parentheses to make the order of operations clear, even when not strictly necessary
- Break complex formulas into smaller steps using intermediate cells:
// Instead of this complex formula:
=IF(AND(A1>B1, C1<D1), (A1+C1)/(B1+D1), A1*C1)
// Use intermediate cells:
E1: =A1>B1
F1: =C1<D1
G1: =(A1+C1)/(B1+D1)
H1: =A1*C1
I1: =IF(AND(E1,F1), G1, H1)
- Test complex conditions with simple values to verify they work as expected
- Use cell comments to explain complex logical expressions
- Consider using named ranges to make formulas more readable:
// Instead of:
=IF(AND(A1>B1, C1<D1), E1, F1)
// Use named ranges:
=IF(AND(Revenue>Expenses, CurrentYear<PreviousYear), Profit, Loss)
Understanding operators and how they interact is fundamental to creating powerful spreadsheet solutions that can handle complex calculations and decision-making processes.