Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission Spreadsheet Computing spreadsheets can be used exclusively for data formatting and layout however, their most common application is to process data what does this mean? in the context of spreadsheets, it means that the spreadsheet provides new information based on what we supply this information can be in the form of data, but also in formatting (e.g. display negative numbers in red) Formula a statement in a cell that performs a computation every formula has a value e.g. math equation, table lookup, etc … the result of the computation this is the value that is displayed the formula itself will be displayed in the formula bar formulas can be combined indicated by an initial = sign in other words, when the data in a cell begins with =, Excel interprets the remainder to be a formula Formulas - Constant constant: a formula whose value is itself examples include: numbers text dates by themselves, constants are not typically expressed as a formula they are usually used in other formulas Numeric Constant a number Numeric Constants by themselves, numeric constants aren’t that useful as formulas they have the same functionality outside of formula instead, they are usually used as part of another formula these include: numeric operators function inputs Numeric Operators Excel accepts the standard math operators +, -, * (times), / (divide), ^ exponent these operators are used in typical binary format e.g. to compute 3+4, enter the formula =3+4 Numeric Operators Question: what happens if I omit the equal sign? Excel interprets the formula as text, as it cannot be interpreted directly as a number or a date (due to the + in the middle). Remember to use = when using formulae. Numeric Operators Question: what happens when I combine operators? Excel honours the order of operations that you are used to: highest: ^ next: * / lowest: + - Numeric Operators Question: suppose I want to perform operations out of order (e.g. perform the add before the multiply)? Use parentheses to reorder your operations. Operations in parentheses have the highest priority. Numeric Operators Example: compute the average of 1,2,3 and 4. Use parentheses to perform the addition before the division. Numeric Operators Example 2: Recall our transaction spreadsheet. We used all numeric constants. Use formulas to compute the final three amounts: Text Constants text can also be used as a constant in a formula however, not as simple as putting the text after the = sign Whenever you see a computed value that starts with #, it often indicates an error. In this case, Excel does not know that Kev is meant to be text Text Constants when text constants are used in a formula, enclose them in double quotes Text Concatenation like numeric constants, not often used by themselves can be used in concatenation – combine multiple text elements into a single version use the operator & Text Concatenation when using concatenation, you must specify all of the characters you want to appear a common mistake is to forget about spaces Mixing Types what happens when we do the following? Excel will attempt to convert the values based on the operator type. In this example, because & accepts two text items, it converts 1000 to “1000” Mixing Types what happens when we do the following? In this example, because + accepts two numbers, it converts “4” to 4 Mixing Types what happens when we do the following? In this example, because - accepts two numbers, it tries to convert “CS ” to a number. Since this fails, an error is generated. Mixing Types - Precedence question: what’s the output of the following? The & operator has lower precedence than all of the math operators. Hence, the formula is parsed as: “1” & ( “2” – 4 ) “1” & -2 “1” & “-2” “1-2” Functions a preset formula in Excel each function has a name functions accept a set of zero or more inputs surrounded by parentheses separated by commas a function has a value usually, the function performs some computation, and its value is the result of that computation Function - First Example suppose you want to know the square root of a number Excel has a function called sqrt accepts one input – a value or formula Function - Inputs note that the input to a function can be another formula, if you like the inside formula is evaluated before its value is sent to the function Function - Inputs the input to a function can even be another function the inside function is evaluated first its value is sent as the input to the outside function Function - Inputs your function will expect a particular type as its input will convert if necessary Function - Inputs your function will expect a particular type as its input an error occurs if it can’t convert Functions – No Input some functions have no inputs the parentheses are still required, to indicate that it’s a function they always return the same value nothing is placed inside e.g. pi() - returns the value π Functions – Example compute the volume of a cylinder of radius 10.4 and height 25.6 Formula: V = πr2h Functions – Example spot the error in the formula pi is a function, and hence must have parentheses to indicate this Functions – Multiple Inputs some functions accept more than one input each input should be separated by commas example: max returns the maximum value amongst all of its inputs Functions – Multiple Inputs not all inputs need to have the same type e.g. left left accepts a text input S, and a number X, and returns the first X characters in S Boolean Values a type that can be one of the two following values: TRUE FALSE think of it like yes (TRUE) or no (FALSE) these values can be on their own, or in a formula Boolean Values some function inputs require boolean values e.g. vlookup (from your lab) the last parameter indicates whether the value you are looking can be an approximate match approximate: TRUE exact: FALSE Boolean Values instead of specifying Boolean values, they are often computed this is done using comparison operators = (equal) <> (not equal) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) Comparison Operators can be used on text types can be used on mixed types If Statement one of the most useful functions in Excel takes three inputs a Boolean value a “True” value the value of the function if the first input is true a “False” value remember: can be a formula that returns a Boolean the value of the function if the first input is false in other words, it selects either the second or third input as its value, depending on whether its first input is true or false If Statement remember: any of the inputs can be formula themselves Since 3 < 4 is true, the value of this formula is the second input, or sqrt(16) If Statement remember: any of the inputs can be formula themselves Since 3 > 4 is true, the value of this formula is the third input, or max(6,7) Excel Functions there are many functions built into Excel Math abs – returns the absolute value of its input sin, cos, tan – returns the sine/cosine/tan value of its input average – returns the average value of its input Excel Functions there are many functions built into Excel Text len – returns the number of characters in its input string lower – converts all characters in its input to lower case upper – converts all characters in its input to upper case Excel Functions – Help Excel has a handy feature that assists users in function recall clicking on the formula bar label will activate a dialog that lists all of the functions available in Excel this includes a categorization, and a search feature Excel Functions – Help furthermore, selecting a function from this list shows a dialog with a place to insert each input, with a description of what it does