Spring 2013 CS 103 Computer Science – Business Problems Lecture 11: Functions and Formulas in Excel Instructor: Zhe He Department of Computer Science New Jersey Institute of Technology 9/13/2019
Creating Basic Formulas A formula is a series of instructions that you place in a cell in order to perform some kind of calculation. Every formula must begin with the equal sign (=). = 1 + 1 You type in the question, click enter, Excel will tell you the answer!
Arithmetic Operators
Precedence 1. Parentheses 2. Percent 3. Exponents 4. Division and Multiplication 5. Addition and Subtraction = 5 + 2 * 2 ^ 3 – 1 = 5 + 2 * 2 ^ (3 – 1)
Cell References Calculate the sum of two cells = A1 + A2 AutoFill the formula!
Exercise Download Llama_Caloric_Intake.xlsx Insert a formula in cell E2 to calculate how much the caloric intake is per body weight. AutoFill the formula to the end of the list. Format the data in Column E to keep 4 decimal places. Add a title to Column E.
Excel calculates the result of a formula every time you open a spreadsheet or change the data a formula uses.
Exercise Download StudentGrades1.xlsx Calculate the final mark for each student. All data should be in percentage.
Functions To use a function, start by entering the function name. = SUM( cell range you want to add up ) calculates the total for a group of cells. AutoComplete
Cell Ranges Comma (,) Colon(:) Space ( ) separates more than one cell e.g., A1, B7, H9 Colon(:) separates the top-left and bottom-right corners of a block of cells e.g., A1:A5, A2:B3 Space ( ) intersection operator e.g., A1:A3 A1:B10
Cell Ranges (cont.) A:A 2:2 includes all the cells in column A includes all the cells in row 2
SUM() You can combine different ways of range selection. = SUM(A2:A12, B5, 429, 350)
AVERAGE() = AVERAGE( cell range ) ignores all empty cells or text values
The Formulas Tab AutoSum Math & Trig
Formula Errors = A1/A2 Try leaving A2 blank Error code: begins with the number sign (#) and ends with an exclamation point (!)
Logical Operators
IF() IF (condition, yes_value, no_value) = IF (order is less than 5000, original listed price, discounted price) How do we translate this in Excel? = IF(A2<5000, B2, B2*0.9)
Exercise Download First Quarter Sales and Bonus.xlsx Calculate the over target sales. If the over target sales is greater than 0, then the salesman gets 5% commission (based on the over target sales). Calculate the total salary.
Exercise Download Fruit Purchase.xlsx Count the occurrences of each fruit.
Absolute Cell References Relative references What if you have a cell that you want to use in multiple calculations? e.g., currency conversion ratio Absolute cell reference Add the $ character twice: in front of the column and in front of the row e.g., $B$12
Exercise Download StudentGrades2.xlsx
AND() AND() accepts two (or more) conditions, and then returns true if all of them are true. If any condition is false, AND() returns false. e.g., the new commission rules (5% rate) came into effect after the year 2010. = IF( AND(E6>0, F6>2010), E6*5%, 0)
Exercise Download StudentGrades3.xlsx The student passes the course only if he(she) passes both of the tests (having a score of at least 60). Use conditional formatting to highlight the failed ones in yellow.
OR() accepts two (or more) conditions, and then returns true if any one of them is true. OR() returns false only if all conditions are false. = IF (OR(condition 1, condition 2), [value_if_true], [value_if_false])
Exercise Download again Fruit Purchases.xlsx Insert one column named “citrus” between apples and grapes. Fill the column with 1 and 0. Count the total.
NOT() NOT() accepts a condition and reverse it. = IF ( NOT(B2>0), ........ , ......... )
MEDIAN() Median value: the number that falls in the middle. 1, 2, 5, 7, 10 If you have an even amount of numbers, Excel averages the two middle numbers to generate the median. 1, 2, 4, 7
MAX() and MIN() pick the largest or smallest value of a series of cells. MAX(range) MIN(range) ignore any nonnumeric content.
LARGE() and SMALL() What if you want to pick the top 3? LARGE(range, position) SMALL(range, position) e.g., LARGE(A2: A12, 2) SMALL(A2: A12, 1)
Exercise Modify StudentGrades2.xlsx Add the following statistics at the bottom of the table Total Average Median Highest Score Second Highest Score Third Highest Score Lowest Score
ABS() gives you the absolute value of a number. = ABS (-3) Use IF()?
ROUND() rounds a numeric value to whatever level of precision you choose. ROUND(number_to_round, number_of_digits) = ROUND(3.987, 2) = ROUND(A2, -2) rounds 1 through 4 down rounds 5 through 9 up
RAND() gives you a random fractional number that is less than 1, but greater than or equal to 0. 0.778526443457 = RAND() = RAND() * 100 Generate a random whole number from 1 to 10?
COUNT(), COUNTA() and COUNTBLANK() COUNT() counts the number of cells that have numeric input. =COUNT(range) COUNTA() counts cells with any kind of content. COUNTBLANK() counts the number of empty cells. How do you count cells with text?
COUNTIF() Counts only the cells you specify COUNTIF(range, criteria) = COUNTIF(C1:C20, “>500”) = COUNTIF(D1:D20, “=Travel”) = COUNTIF (D1:D20, “=” & A2)
VLOOKUP() Finds a specific row in a large table by Scanning the values in a single column from top to bottom Retrieving other information from the same row Download VLookupExample.xlsx What is the name and price of the product with ID of 3?
VLOOKUP() VLOOKUP(lookup_value, range, column_index_number, FALSE) lookup_value: what you are seeking range: from the column that contains the lookup_value column_index_number: position of the column which contains the data you want to retrieve FALSE: exact match
Summary COUNTIF() counts only the cells you specify. =COUNTIF(range, criteria) VLOOKUP() finds a specific row and retrieves other information from the same row VLOOKUP(search_for, range, column_number)