INTRODUCTION
TO EXCEL FOR
DATA ANALYTICS
TOPIC: INTRODUCTION TO
LOGICAL FUNCTIONS
Indexes
IF Functions 3
Nested IF Functions 12
IFS Functions 16
Text Functions 21
Date & Time Functions 37
Date & Time Formats 40
Logical Functions
Logical functions in Excel work with conditions. They help deal
with different situations accordingly. These functions perform
work similar to IF-ELSEIF-ELSE statements in a programming
language.
All of these functions have simple syntaxes, and they can be
beautifully combined with other functions to obtain desired
results.
Download Dataset: Click Here
IF Functions
The IF function checks whether a condition is met, and returns
one value if true and another value if false.
1. For example, take a look at the IF function in cell C2 below.
Explanation: if the score is greater than or equal to 60, the IF
function returns Pass, else it returns Fail.
Simple IF Function Examples
The IF function checks whether a condition is met, and returns
one value if true and another value if false.
Download Dataset: Click Here
1a. For example, take a look at the IF function in cell B2 below.
Explanation: if the price is greater than 500, the IF function
returns High, else it returns Low.
1b. The following IF function produces the exact same result.
Note: you can use the following comparison operators: = (equal
to), > (greater than), < (less than), >= (greater than or equal to), <=
(less than or equal to), and <> (not equal to).
2. Always enclose text in double quotation marks.
3a. The formula below calculates the progress between two
points in time.
3b. You can use the IF function to display an empty string if the
end value hasn't been entered yet (see row 5).
Explanation: if the end value is not empty (<> means not equal to),
the IF function calculates the progress between the start and end
value, else it displays an empty string (two double quotes with
nothing in between).
AND Operator
The AND Operator returns TRUE if all conditions are true and
returns FALSE if any of the conditions are false.
1. For example, take a look at the AND function in cell D2 below.
Explanation: the AND function returns TRUE if the first score is
greater than or equal to 60 and the second score is greater than or
equal to 90, else it returns FALSE.
OR Operator
The OR function returns TRUE if any of the conditions are TRUE
and returns FALSE if all conditions are false.
1. For example, take a look at the OR function in cell D2 below.
Explanation: the OR function returns TRUE if at least one score is
greater than or equal to 60, else it returns FALSE.
2. Combine the OR function with the IF function.
Explanation: the OR function returns TRUE or FALSE (see
previous example). If TRUE, the IF function returns Pass, if
FALSE, the IF function returns Fail.
3. For example, take a look at the OR function in cell E2 below.
Explanation: the OR function returns TRUE if at least one score is
greater than or equal to 90, else it returns FALSE. The OR
function can test up to 255 conditions. The only way for the OR
function to return FALSE is if all the conditions are FALSE (row 6).
4. The array formula below uses the OR function to return TRUE if
any cell in the range A1:E6 is greater than or equal to 90.
Explanation: finish an array formula by pressing CTRL + SHIFT +
ENTER. Excel adds the curly braces {}. In Excel 365 or Excel 2021,
finish by simply pressing Enter. You won't see curly braces. The
value in cell D4 is greater than or equal to 90. As a result, the
array formula returns TRUE.
5. Combine the OR function with the AND function.
Explanation: the AND Function returns TRUE if all conditions are
true and returns FALSE if any of the conditions are false. The
AND function above has two arguments separated by a comma
(Table, Green or Blue). The AND function returns TRUE if
Product equals "Table" and Color equals "Green" or "Blue".
6. Combine the OR function with the WEEKDAY function.
Explanation: the WEEKDAY function in Excel returns a number
from 1 (Sunday) to 7 (Saturday) representing the day of the week
of a date. As a result, the OR function returns TRUE if the date falls
on a weekend.
7. Don't confuse the OR function with the XOR (Exclusive OR)
function.
Explanation:
The XOR function returns TRUE if an odd number of conditions
are true, and FALSE otherwise.
With two conditions (see example above) the XOR function
returns TRUE if one condition is true (row 2) and returns FALSE.
If both conditions are false (rows 3, 4, and 6) or both conditions
are true! (row 5).
AND/OR Criteria
Use the IF function in combination with the AND function and
the OR function and become an Excel expert.
1. For example, take a look at the IF function in cell D2 below.
Explanation:
The AND function returns TRUE if the first score is greater than
or equal to 60 and the second score is greater than or equal to 90,
Otherwise, it returns FALSE. If TRUE, the IF function returns
Pass, if FALSE, the IF function returns Fail.
2. For example, take a look at the IF function in cell D2 below.
Explanation:
The OR function returns TRUE if at least one score is greater
than or equal to 60, else it returns FALSE. If TRUE, the IF function
returns Pass, if FALSE, the IF function returns Fail.
3. For example, take a look at the IF function in cell D2 below.
Explanation: the AND function above has two arguments
separated by a comma (Table, Green or Blue). The AND function
returns TRUE if Product equals "Table" and Color equals "Green"
or "Blue". If TRUE, the IF function reduces the price by 50%, if
FALSE, the IF function reduces the price by 10%.
Nested IF Functions
The IF function in Excel can be nested, when you have multiple
conditions to meet. The FALSE value is being replaced by
another IF function to make a further test.
1. For example, take a look at the nested IF formula in cell C2
below
2. For example, take a look at the nested IF formula in cell C2
below.
Explanation: if the score is less than 60, the nested IF formula
returns F, if the score is greater than or equal to 60 and less than
70, the formula returns D, if the score is greater than or equal to
70 and less than 80, the formula returns C, if the score is greater
than or equal to 80 and less than 90, the formula returns B, else it
returns A.
Let's take a few more examples on IF Functions.
1. For example, use IF and AND to test if a value is between two
numbers.
Explanation:
The AND function returns TRUE if the person is older than 12 and
younger than 20, else it returns FALSE. If TRUE, the IF function
returns Yes, if FALSE, the IF function returns No.
2. You can combine IF with AVERAGE, SUM, and other Excel
functions. The sky is the limit!
Explanation:
The AND function returns TRUE if the input value is greater than
100 and the average of the values in the named range Data1 is
greater than 100, else it returns FALSE. If TRUE, the IF function
returns the sum of Data2, if FALSE, the IF function returns 0.
Confused? You can always use the Evaluate Formula tool to step
through your IF formula. This Excel tool helps you understand a
formula.
3. For example, select cell G3 above.
4. On the Formulas tab, in the Formula Auditing group, click
Evaluate Formula.
5. Click Evaluate multiple times.
Note: try it yourself. Download the Excel file and choose one of
the IF formulas explained on this page. You can use this tool to
step through all kinds of formulas.
IFS Functions
Use the IFS function in Excel 2016 or later when you have
multiple conditions to meet. The IFS function returns a value
corresponding to the first TRUE condition.
Note: if you don't have Excel 2016 or later, you can nest the IF
function.
Download Dataset: Click Here
1a. If the value in cell A1 equals 1, the IFS function returns Bad.
1b. If the value in cell A1 equals 2, the IFS function returns Good.
1c. If the value in cell A1 equals 3, the IFS function returns
Excellent.
1d. If the value in cell A1 equals another value, the IFS function
returns a No Valid Score.
Note: instead of TRUE, you can also use 1=1 or something else that
is always TRUE.
Here's another example.
2a. If the value in cell A1 is less than 60, the IFS function returns F.
2b. If the value in cell A1 is greater than or equal to 60 and less
than 70, the IFS function returns D.
2c. If the value in cell A1 is greater than or equal to 70 and less
than 80, the IFS function returns C.
2c. If the value in cell A1 is greater than or equal to 70 and less
than 80, the IFS function returns C.
2d. If the value in cell A1 is greater than or equal to 80 and less
than 90, the IFS function returns B.
2e. If the value in cell A1 is greater than or equal to 90, the IFS
function returns A.
Note: to slightly change the boundaries, you might want to use "
<=" instead of "<" in your function.
NOT Operator
The NOT function changes TRUE to FALSE, and FALSE to TRUE.
1. For example, take a look at the NOT function in cell D2 below.
Explanation: in this example, the NOT function reverses the
result of the OR function.
IFERROR
Excel IFError Function helps to return a value if a formula returns
an Error.
For example, if we enter some formula in Cell, and we assume
that there is some chance of getting an Error. In this case, we can
use IFERROR function to return something else when the formula
evaluates an error.
=IFERROR(Actual Formula, Value if the formula returns an
Error)
Example:
Let us say you are accepting Total Sales at Range A1 and Units in
Range B1. And You want to calculate the Unit Price at C1. Your
formula at C1=A1/B1.
If the user enters 2000 at Range A1 and 10 at B1, the formula C1
evaluates and returns the unit price as 200.
What if the user enters 2k at Range A1 and 10 at B1, the formula C1
evaluates to an Error (#VALUE!).
In this case, we can use IFERROR function to instruct the user to
enter valid numbers.
You can use the formula =IFERROR(A1/B1,” Please Enter Valid
Number”) to ask the user to enter valid data.
Syntax:
Here is the syntax of the Excel IFERROR Function. It has two
required parameters.
=IFERROR(value, value_if_error)
Parameters:
Excel IFERROR Function takes two parameters. Value is a formula
to check for an error. And the second one is the value to be
returned if the first argument evaluates an error.
value:
Value is a required parameter. This is the Argument which is to be
evaluated for an Error. Often, it is a formula or expression.
value_if_error:
This is a required parameter. This is the value to return if the
formula evaluates to an error. IFERROR returns this value if the
first argument evaluates to #N/A, #VALUE!, #REF!, #DIV/0!,
#NUM!, #NAME? or #NULL!.
Text Functions
Excel has many functions to offer when it comes to manipulating
text strings.
Download Dataset: Click Here
JOIN Strings
To join strings, use the & operator.
LEFT Function
To extract the leftmost characters from a string, use the LEFT
function.
RIGHT Function
To extract the rightmost characters from a string, use the
RIGHT function.
MID Function
To extract a substring, starting in the middle of a string, use the
MID function.
LEN Function
To get the length of a string, use the LEN function.
Note: space (position 8) included!
FIND Function
Download Dataset: Click Here
1. To find the position of a substring in a string, use the FIND
function.
Note: string "am" found at position 3.
2. The FIND function below finds the string "Excel" at position 11.
3. The FIND function is case-sensitive. The FIND function below
returns the #VALUE! error because it cannot find the string
"excel".
The FIND function has a 3rd optional argument. You can use this
argument to indicate the position, counting from the left, at
which you want to start searching.
4. The FIND function below finds the string "o" at position 5.
5. The FIND function below starts searching at position 6 and
finds the string "o" at position 7.
SUBSTITUTE Function
To replace existing text with new text in a string, use the
SUBSTITUTE function.
Note:
Instead of using the & operator, use the CONCATENATE
function in Excel.
CONCATENATE Function
Download Dataset: Click Here
Use CONCATENATE, CONCAT, TEXTJOIN, or the & operator in Excel to
concatenate (join) two or more text strings.
1. The CONCATENATE function below concatenates the string in cell A1
and the string in cell B1.
2. Use the & operator to produce the exact same result.
3. The CONCATENATE function below concatenates the string in
cell A1, the string " and " (enclose text in double quotation marks),
and the string in cell B1.
4. Use the & operator to produce the exact same result.
5. The CONCATENATE function below concatenates the string
in cell A1, a space and the string in cell B1.
6. Use the & operator to produce the exact same result.
The CONCAT function in Excel 2016 or later produces the exact
same result as the CONCATENATE function. Simply replace
CONCATENATE with CONCAT in the formulas shown above.
7. The CONCAT function can also join a range of strings. If you
don't need a delimiter (space, comma, dash, etc).
The TEXTJOIN function in Excel 2016 or later joins a range of
strings using a delimiter (first argument).
8. First, take a look at all the extra spaces in column E below
when you drag the CONCATENATE function in cell E2 down to
cell E11.
9. The beauty of the TEXTJOIN function is that it can ignore
empty cells (if the second argument is set to TRUE).
The TEXTJOIN function in Excel 2016 or later joins a range of
strings using a delimiter (first argument).
8. First, take a look at all the extra spaces in column E below
when you drag the CONCATENATE function in cell E2 down to
cell E11.
9. The beauty of the TEXTJOIN function is that it can ignore
empty cells (if the second argument is set to TRUE).
10. When using the CONCATENATE function, use the TEXT
function to format numbers.
Note: use 0 to display the nearest integer value. Use 0.0 for one
decimal place. Use 0.00 for two decimal places, etc.
11. Use CHAR(10) to insert a line break.
Note: don't forget to enable text wrapping. On the Home tab, in the
Alignment group, click Wrap Text.
12. Let's take a look at one more cool example that uses the
TEXTJOIN function. First, the IF function below finds all members
of Team 1.
Explanation:
The IF function checks each cell in the named range Teams.
If equal to the value in cell E3, it returns the name from the
named range Names, else it returns an empty string (two
double quotes with nothing in between).
13. The IF function returns an array constant stored in Excel's
memory.
Select the formula in the formula bar and press F9 to see this
array constant.
14. Add the powerful TEXTJOIN function to concatenate these
names.
Use a comma and space as the delimiter (first argument) and
set the second argument to TRUE to ignore the empty strings.
Finish an array formula by pressing CTRL + SHIFT + ENTER.
Note: Excel adds the curly braces {}. In Excel 365 or Excel 2021,
finish by simply pressing Enter. You won't see curly braces. Mia,
James, and Sophia are in Team 1. Double-click the lower right
corner of cell F3 to quickly copy this formula to the other cells.
TEXT Function
Download Dataset: Click Here
When joining text and a number, use the TEXT function in Excel
to format that number. This page contains many easy-to-follow
TEXT function examples.
1a. For example, without using the TEXT function this would be
the result.
1b. With the TEXT function.
Note: #,## is used to add commas to large numbers. Always
enclose the format code (second argument) in double quotation
marks.
2. Here's another example. Apply a percentage format.
3. And another example. Format a date.
Note: use less/more m's, d's, and y's to change the appearance
of the date.
4. For example, use the TEXT function to only display the day of
the week. This time we simply use the TEXT function without
adding text.
5. Use the TEXT function to display a number in scientific
notation.
6. Use the TEXT function to display a fraction and add the TRIM
function to remove the leading space.
Simply use the 'Format Cells' dialog box to find the right format
code.
7a. For example, enter a time into cell A1 and select cell A1.
7b. Right-click, and then click Format Cells (or press CTRL + 1).
7c. Select the Custom category and click a format code. Next,
click in the Type box, select the format code, and press CTRL +
c to copy this code.
Note: Excel gives you a live preview of how the time will be
formatted (under Sample).
7d. Click Cancel.
7e. Paste (CTRL + v) the format code into your TEXT function.
Don't forget to enclose the format code in double quotation
marks.
Text to Columns
Download Dataset: Click Here
To separate the contents of one Excel cell into separate columns, you can
use the 'Convert Text to Columns Wizard'. For example, when you want to
separate a list of full names into last and first names.
1. Select the range with full names.
2. On the Data tab, in the Data Tools group, click Text to Columns.
The following dialog box appears.
3. Choose Delimited and click Next.
4. Clear all the checkboxes under Delimiters except for the
Comma and Space check box, and Click Finish.
Note:
This example has commas and spaces as delimiters. You may
have other delimiters in your data. Experiment by checking and
unchecking the different checkboxes. You get a live preview of
how your data will be separated.
Result:
Date & Time Functions
Download Dataset: Click Here
To enter a date in Excel, use the "/" or "-" characters. To enter a
time, use the ":" (colon). You can also enter a date and a time in
one cell.
Note: Dates are in US Format. Months first, Days second. This
type of format depends on your windows regional settings.
Year, Month, Day
To get the year of a date, use the YEAR function.
Note: use the MONTH and DAY functions to get the month and
day of a date.
DATE Function
1. To add the number of days to a date, use the following simple
formula.
2. To add a number of years, months, and/or days, use the
DATE function.
Note: the DATE function accepts three arguments: year, month,
and day. Excel knows that 6 + 2 = 8 = August has 31 days and rolls
over to the next month (23 August + 9 days = 1 September).
CURRENT DATE & TIME
To get the current date and time, use the NOW function.
Note: use the TODAY function to enter today's date in Excel.
HOUR, MINUTE & SECOND
To return the hour, use the HOUR function.
Note: use the MINUTE and SECOND functions to return the
minute and second.
TIME Function
To add a number of hours, minutes, and/or seconds, use the
TIME function.
Note: Excel adds 2 hours, 10 + 1 = 11 minutes, and 70 - 60 = 10
seconds.
DATE & TIME Formats
Download Dataset: Click Here
Dates and times in Excel can be displayed in a variety of ways. To
apply a Date or Time format, execute the following steps.
1. Select cell A1.
2. Right-click, and then click Format Cells.
3. In the Category list, select Date, and select a Date format.
4. Then, Finally Click on "OK".
Note: to apply a Time format, in the Category list, select Time.
5. Dates are stored as numbers in Excel and count the number of
days since January 0, 1900. Times are handled internally as
numbers between 0 and 1. To clearly see this, change the
number format of cells A1, B1, and C1 to General.
Note: apparently, 42544 days after January 0, 1900 is the same as
June 23, 2016. 6:00 is represented as 0.25 (quarter through the
day).
6. You can enter times as 6:00, but Excel displays this time as
6:00:00 AM in the formula bar. AM is used for times in the night
and morning. PM is used for times in the afternoon and evening.
7. Change the number format of cell C1 to Date only.
Note: cell C1 still contains the number 42544.25. We only
changed the appearance of the number, not the number itself.
“No one is to
blame for your
future situation
but yourself. If
you want to be
successful, then
become
‘Successful.”
By Jaymin Shah