11
Lesson 2: Functions & Formulas Things to know by the end of this course: - If, Nested If - And, Or - VlookUp, HlookUp - SumIf, AverageIf, CountIf - SumProduct If The IF function, allows us to evaluate data depending of a condition. An IF function requires us to specify three parameters: condition to be met, return value if true, and return value if false. For example: =IF(logical_test, value_if_true, value_if_false) For a simple If function there will always be only 2 possible answers Imagine the following example: A company decides to offer a bonus to employees depending of their seniority. If they have 3 years or more seniority, they are entitled to a bonus of $200. We would like to add a column indicating automatically if they are entitled to a bonus or not. Therefore we need to find: Logical test ………….. =>Is the seniority >= to 3 Value if true …………=> 200 Value if false ……….. => 0

Excel Course Logic Functions

  • Upload
    gaelle

  • View
    265

  • Download
    8

Embed Size (px)

Citation preview

M 2 Excel Course Intermediate Level

08Automne

Lesson 2: Functions & Formulas

Things to know by the end of this course: If, Nested If And, Or VlookUp, HlookUp SumIf, AverageIf, CountIf SumProduct

If

The IF function, allows us to evaluate data depending of a condition. An IF function requires us to specify three parameters: condition to be met, return value if true, and return value if false.

For example:

=IF(logical_test, value_if_true, value_if_false)

For a simple If function there will always be only 2 possible answers

Imagine the following example:A company decides to offer a bonus to employees depending of their seniority.

If they have 3 years or more seniority, they are entitled to a bonus of $200.

We would like to add a column indicating automatically if they are entitled to a bonus or not.Therefore we need to find:

Logical test .. =>Is the seniority >= to 3Value if true => 200Value if false .. => 0

Now imagine we do not want to put the amount, but a yes if they are entitled to the bonus, a no if they are not entitled to the bonus.

Logical test .. =>Is the seniority >= to 3Value if true => YesValue if false .. => No

If you want to write text, you need to use .

The formula should be entered in the first cell and dragged down to the others.

Nested If

If you have 3 possible answers, you need to use a Nested If (an IF in an IF)

Now imagine, we would not only have 2 possibilities, but three possibilities:

If the employees have 0-2 years of seniority, they have $0 bonusIf the employees have 3-4 years of seniority, they have a bonus of $200If the employees have more than 4 years seniority, they have a bonus of $500

And, Or

If you have several conditions, but still 2 possible answers at the end, you do not need to use a nested IF.

Into the logical test of the If Function you can add one of these formulas

AND: All conditions need to be true=AND(condition1,condition2,condition3)

OR: one of the conditions should be true=OR(condition1,condition2,condition3)

LookUp

If you have 3 or more possible answers, you need to use a LookUp Function (VLookUp or HLookUp)

For example:

For each year of seniority, we have a different level of bonus.

It would not be very handy to write an If formula in a If, in a If, in a IF

In this case we will use another formula that is called Lookup.Because our data is displayed in a Vertical way, we use VlookUp. If it had been in horizontal way, we would have used HlookUp.

This is how we will write a VLookUpformula:

=VLOOKUP(lookup_value, table_array, column_index_number, range_lookup)

To start building it, your conditions need to be very clear in your head. What are you trying to achieve?

If the seniority is 0 years, the employees will have a $0 bonus, if the seniority is 1, he will have a $50 bonus

Lookup value Seniority

Table array The table copied just above

Column index number: In which column of the table will we find the answer to our question.

Range-lookup: You can choose between true and false. False is indicating an exact match, while true is indicating an approximate match

We will add a new column, indicating the level the employees reach in the company. There are 3 levels. From 0 to 2 years seniority => level 1 From 3 to 4 years seniority => level 2 More than 4 years seniority => level 3

You have 3 possible answers, you could thus use an If formula or a VLookUp formula. We will try both possibilities.

The If Formula:

The VLookUP Formula:

In all our examples, we have considered that the years of seniority were plain numbers. What happens with your formulas if you change the years of seniority of the employees in numbers with decimals?

The computer cannot make the formula work, because he cannot fine exactly 2,4 in the Table Array.

But, if you Use TRUE in the formula, instead of FALSE, he will not look for the exact value, but the approximate value.

Try to change the Range lookup from False to True.

To remember: Always pay attention to absolute references in order to be able to drag and down properly Always analyse if you want an exact match or an approximate figure (false or true) The lookup value always needs to correspond to the first column of your table array

Sum, SumIf, Count, CountIf, Average, AverageIf

Now, we would like to have a summary of the bonuses to pay out per level.

If you want to apply a Sum, depending of a condition, you need to use SUMIF (be careful, make your table as variable as possible by applying absolute References)

The same type of Formula exists if you want to count depending of a condition, or if you want to average depending of a condition.

SumProduct

A last very useful formula for this lesson is SumProduct

Imagine the following:

You would like to calculate directly in one cell the Sum of the products:(1*10)+(2*20)+(3*30)+(4*40)+(5*50)

It is possible by using SumProduct.

Try!

Useful Shortcuts

Shift and F3: To go directly to FxShift and Spacebar / Ctrl and Spacebar: Hold Shift and Spacebar to highlight a row or hold Ctrl and Spacebar to highlight a column.Ctrl + :: Date of TodayCtrl + : Toggle Show Formula in cell instead of values

6

M 2 Excel Course Intermediate Level9