You are on page 1of 30

WELCOME TO THE

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.

The Insert Function dialog box opens


Click the Insert Function button on the formula bar.
In the Search for a function box, type a description of
what you want to do.
Insert A Function
•In this example, you could type “SUM" or some other keywords.
Click Go.
 Click OK, Enter the argument values in the Function Argument
dialog box, and then click the OK button.
Tips
•You can also select a function category in the formula bar,
Select the appropriate function from the list of functions.
•This action will display a list of related functions, which you can
then browse through.
• Press Shift +F3,
• Enter a description of the function, and then click the Go button.
The Function

FUNCTION EXAMPLE DESCRIPTION


SUM =SUM(A1:A10) Finds the sum of cells A1 through
A10
AVERAGE =AVERAGE(B1:B10) Finds the average of cells B1
through B10
MAX =MAX(C1:C10) returns the highest number from
cells C1 through C10
MIN =MIN(D1:D10) returns the lowest number from
cells D1 through D10
SQRT =SQRT(D10) Finds the square root of the
value in cell D10
TODAY =TODAY() Returns the current date (leave
the parentheses empty)
Text isn't part of numerical calculations
(obviously)

Formula to formula view (press Cntrl-`)


add up all
numbers in
column C

(Same Spreadsheet)

Text data values view (press Cntrl-`)


in C1 is
not
included in
the Sum

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

AND is "nested" inside of the IF


These parentheses "belong to" the if
IF with AND - spreadsheet views

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..

c. Advanced Math Operations:

=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.

d. Dynamic Range Calculations:

=SUM(INDEX(A:A, MATCH(8, B:B, 0)):INDEX(A:A, MATCH(8, B:B, 0)+2))


This formula sums a dynamic range of values in column A based on criteria in column B.

e. Data Validation:

=AND(ISNUMBER(A1), OR(A1>0, B1="Valid"))


This formula validates data in column A based on numeric values and specific conditions
in column B.
Example 1 & 2
The examples below checks if the marks are 50 and above the student must
pass the exam otherwise the student fail the exam.
A B A B C D
1 ACTUAL PREDIC FORMULAR RESULT
1 Marks Grade EXPENSIS TE
2 49 =If(A1<=50,"FAIL","PASS") D
Then Press ENTER. Put the mouse at 2 1500 900 =IF(A2>B2,"Over Over Budget
the corner of the cell then drag it down. Budget","OK")
3 500 900 =IF(A3>B3,"Over OK
3 51 Budget","OK")
4 500 925 =IF(A4>B4,"Over OK
NESTED IF Example 3 Budget","OK")

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

HALIMA Male REGISTRER 789


AHMED Male MANAGER 980
ARAFA Female DIRECTOR 300
BAKARI Male MANAGER 899
KIJAKAZI Female REGISTRER 910
FAHIMA Female REGISTRER 980
MUZNA Female REGISTRER 755
KOMBO Male MANAGER 920
ABDOU Male DIRECTOR 611
ZAHRA Female MANAGER 340

Qn1. House allowance is 10% of salary for all.

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

1. VLOOKUP: Vertical Lookup


Example:
Assume you have a table of product sales data where you want to
look up the price of a product based on its name.
=VLOOKUP("ProductA", A1:C10, 2, FALSE)

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.

• Example: Summing a Range with an Array Formula


• Assume you have a range of numbers in cells A1:A5. Instead of using
=SUM(A1:A5), you can use an array formula:
• =SUM(A1:A5)
• But, with an array formula, you enclose the range in curly braces {} and
press Ctrl + Shift + Enter:
• {=SUM(A1:A5)}
Array
• Array Functions: SUMPRODUCT

• The SUMPRODUCT function is a powerful array function that


multiplies corresponding components in the given arrays and
returns the sum of those products.

• Example: Weighted Sum of Products

• 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

• 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.
Thank You
• May Allah Bless You All

You might also like