Professional Documents
Culture Documents
SECOND LECTURE
What is a function?
• A function is a predefined formulas that perform
calculations by using specific values, called arguments, in
a particular order or structure.
• Functions can be used to perform simple or complex
calculations.
• The structure of a function begins with an equal sign (=),
followed by the function name, an opening parenthesis, the
arguments for the function separated by commas, and a
closing parenthesis.
• Functions have
– a name
– parentheses
2
What is a function?
• Built-in Excel Functions can be a faster way of doing
mathematical operations than formulas.
• Example- if you wanted to add the values of cells D1
through D10, you could type the formula
"=D1+D2+D3+D4+D5+D6+D7+D8+D9+D10"
• A shorter way would be to use the SUM function and
simply type "=SUM(D1:D10)".
SUM( ) function
The SUM( ) function is probably the most common
function in Excel.
What is a function?
• To build a SUM( ) function, begin by typing the =
sign, Next type the word SUM followed by an open
parenthesis.
• You must now tell Excel which cells to sum.
• Using the mouse, click and drag over the range of
cells you wish to add.
• A dotted outline will appear around the cells and the
cell range will be displayed in the formula bar.
What is a function?
When you have the correct cells selected, release the
mouse button, type a closing parenthesis and press
the <Enter> key.
If you do not want to use the mouse, type in the
references of the cells you want to sum. For
example, to add cells B3 through B5, type
=SUM(B3:B5).
Excel interprets B3:B5 as the range of cells from B3
to B5.
Insert A Function
• Excel has hundreds of prewritten formulas which
make it easy to do complex procedures with numbers,
dates, times, text, and more.
(Same Spreadsheet)
9
Working with AutoFill
• AutoFill copies content and formats from a cell or
range into an adjacent cell.
• Select the cell or range that contains the formulas
you want to copy.
• Drag the fill handle in the direction you want to
copy the formula(s) and then release the mouse
button.
• To copy only the formats or only the formulas, click
the AutoFill Options button and select the
appropriate option.
Working with AutoFill
• Or Select the cell or range that contains the
formulas you want to copy
• In the editing group on the Home tab, click
the Fill button
• Select the appropriate fill direction and fill
type and then click the OK button.
CONCATENATE Function
• You can use the CONCATENATE function instead
of the ampersand (&).
• The following formulas are equivalent:
=A1&B1&C1
=CONCATENATE(A1,B1,C1)
• The CONCATENATE function can take as many
parameters as you like.
12
Working with Logical Function
• A logical Function is a function that works
with values that are either true or false
• It is a logical function that returns one value
if the statement is true and returns a
different value if the statement is false
• IF(logical_test,value_if_true,
[Value_if_false]
Logical operators
• In Excel the following "operators" are used
Operator Meaning
> greater than
< less than
>= greater than or equal to
<= less than or equal to
= equal to
<> not equal to
• Examples
3>2 true
3<2 false
14
Logical Formulas
Formula View Values View
15
Parameters for IF function
Manually
Formula View Values View
16
IF with AND - nested function calls
• You can use an AND inside of an IF.
• This is called a NESTED FUNCTION Example
17
Nested IF Function
use a dataset with columns for numerical values, categories, and boolean values.
A B Example 1
5 Yes
=IF(A1>0, "Positive", IF(A1<0, "Negative", "Zero"))
This formula applied to cell C1 would categorize the value in
-10 No
A1 as "Positive," "Negative," or "Zero" based on its sign
15 Yes
Example 2: Nested SUM and IF Function
8 No
=SUM(IF(A1:A5>10, A1:A5, 0))
20 Yes This formula sums only the values in the range A1:A5 that
are greater than 10.
Use Cases:
a. Conditional Calculations:
=IF(AND(A1>10, B1="Yes"), "Category A", IF(OR(A1<=10, B1="No"), "Category B",
"Other"))
This formula categorizes data into "Category A," "Category B," or "Other"
……………………………………………………………………………………………………
b. Calculations Based on Multiple Criteria:
=IF(AND(A1="Sales", B1="Yes"), A1*0.1, IF(AND(A1="Expenses", B1="No"), A1*0.05,
"No Bonus"))
This formula calculates bonuses based on criteria related to sales and expenses.
Nested IF Function Cont..
=SQRT(SUM(POWER(A1:A5, 2)))
This formula calculates the square root of the sum of the squares of values in the range
A1:A5.
e. Data Validation:
If you have more than one condition you have to use nested if, nested if checks for the first
condition then comes to the next finally finish by taking the last condition if the previous
condition not met.
A B C D
1 Name Mark s Formula to calculate grade Result
2 Ahmad 89 =IF(B2>=70,"A",IF(B2>=50,"B",IF(B2>=30,"C","F"))) A
3 Aisha 61 B
4 Omar 42 C
5 Fahima 53 B
6 Komb 23 F
7 Rabiha 71 A
Exercise 1
Name sex Post salary House transp Meal tax
Qn2 transport allowance is 30% of salary for male and 20% of salary for female Qn3
meal allowance is 25% of salary for REGISTRER and 15% of salary for MANAGERS
and 10%of salary for DIRECTORS and 5% For others
VLOOKUP, HLOOKUP, INDEX, and MATCH
In this example:
"ProductA" is the lookup value.
A1:C10 is the table range.
2 indicates the column containing the values to be returned
(price).
FALSE ensures an exact match.
Practical Application:
Use VLOOKUP to fetch information such as prices, quantities, or descriptions from a database
based on a specific identifier.
Now, let's use these datasets for the examples:
• VLOOKUP
• Type in excel :
• =VLOOKUP("ProductA", A1:F5, 2, FALSE)
• This formula looks up the price of "ProductA" in the sales
data table.
• HLOOKUP:
• Type in excel :
• =HLOOKUP("January", A1:F5, 3, FALSE)
• This formula looks up the sales for the month of January
in the sales data table.
• INDEX and MATCH:
• Type in excel :
• =INDEX(B2:B5, MATCH(123, A2:A5, 0))
• This formula finds the department of the employee with ID 123
in the employee data table.
• MATCH:
• Type in excel :
• =MATCH("ProductC", A1:A4, 0)
• This formula finds the position of "ProductC" in the list of
products.
Array
• Basic Array Formula Syntax:
• Instead of working with individual cells, array formulas operate on entire
ranges of data.
• You create an array formula by entering the formula and then pressing Ctrl +
Shift + Enter instead of just Enter.
• Assume you have two arrays, one with quantities (B1:B5) and
the other with prices (C1:C5), and you want to calculate the
total cost:
• =SUMPRODUCT(B1:B5, C1:C5)
• In this formula:
• B1:B5 represents the quantities.
• C1:C5 represents the prices.
• SUMPRODUCT multiplies the corresponding components and
returns the sum of the products.
– Practical Applications:
– SUMPRODUCT is commonly used for weighted averages, calculating the dot
product of two arrays, or applying complex conditions to arrays.
– Example: Conditional Sum using SUMPRODUCT
– Assume you want to sum only the quantities where the corresponding price is
greater than 10:
– =SUMPRODUCT((C1:C5>10) * B1:B5)
– In this example, (C1:C5>10) creates an array of TRUE/FALSE values based on
the condition, and then * B1:B5 multiplies these values with the quantities.
SUMPRODUCT then sums the results.
• Example: Conditional Sum using SUMPRODUCT
• =SUMPRODUCT((C1:C5>10) * B1:B5)
• In this example, (C1:C5>10) creates an array of TRUE/FALSE
values based on the condition, and then * B1:B5 multiplies these
values with the quantities. SUMPRODUCT then sums the results.
Thank You
• May Allah Bless You All