logic functions practice.xls

Upload: ali-usman

Post on 07-Aug-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/20/2019 Logic Functions Practice.xls

    1/33

    Excel Logical Functions

    Contents Guide to topics: For a result that...

    ...is a logical value (true or false) use

    AND, OR, NOT

    ...is another calculation or another value us

    * IF, AND, OR 

    *

    * ...filters and calculates use

    COUNTIF, SUMIF

    ...is a calculation that multiplies and adds u

    SUMPRODUCT

    * For more on the olive oil logic exercises see the

     "Proficiency xercises ! olutions" document ! #or$%oo$.

    Function Introduction

     AND

     AND OR NOT

    IF

    Nested IFs

    Olive Oil Logic - 1

    Olive Oil Logic - 2

    Olive Oil Logic - 3

    IF Budget

    IF AND

    SUMIF

    OUNTIF

    SUM!RODUT

  • 8/20/2019 Logic Functions Practice.xls

    2/33

    e

  • 8/20/2019 Logic Functions Practice.xls

    3/33

    About functions

    Functions are predefined formulas that perform calculations

    %y using specific values& called arguments& in a particular order&

    or structure. Functions can %e used to perform simple or complexcalculations.

    follo#ed %y the function name& an opening parenthesis& the arguments

    for the function separated %y commas& and a closing parenthesis.

      ' or F+& arrays& error values such as ,-& or cell references.

    'he argument you designate must produce a valid value for that argument.

      rguments can also %e constants& formulas& or other functions.

      the /nsert Function dialog %ox helps you enter #or$sheet functions.

    s you enter a function into the formula& the /nsert Function dialog %ox

    displays the name of the function& each of its arguments& a description

      of the function and each argument& the current result of the function&

    and the current result of the entire formula.

      /n certain cases& you may need to use a function as one of the arguments

      of another function. For example& the follo#ing formula uses a nested

    0G function and compares the result #ith the value 12.

      the same type of value that the argument uses. For example& if the argument

    returns a ' or F+ value& then the nested function must return a '

    or F+. /f it doesn3t& 4icrosoft xcel displays a ,0+5 error value.

      functions. 6hen Function 7 is used as an argument in Function &

    Function 7 is a second8level function. For instance& the 0G function

    and the 4 function are %oth second8level functions %ecause they are

    function #ould %e a third8level function& and so on.

    Stuctue! 'he structure of a function %egins #ith an e9ual sign ()&

    Function na"e. For a list of availa%le functions& clic$ a cell and press ;/F'

  • 8/20/2019 Logic Functions Practice.xls

    4/33

      arguments of the /F function. function nested #ithin the 0G

    Note&

    'o s#itch %et#een vie#ing the results of a function or formula and

    vie#ing the formulas that return the results& choose one of the

    follo#ing techni9ues:

    ?. Press C'+

  • 8/20/2019 Logic Functions Practice.xls

    5/33

      Contents

  • 8/20/2019 Logic Functions Practice.xls

    6/33

  • 8/20/2019 Logic Functions Practice.xls

    7/33

    Excel's AND Function

    Fo"ula Desci'tion (Result)

    "AND#TRU$% TRU$& All 'rgu(ents 're true) Result* TRU$

     "AND#TRU$% FALS$& One 'rgu(ent is +'lse) Result* FALS$

    "AND#2,2"% 2,3".& All 'rgu(ents ev'lu'te to true) Result* TRU$

    "AND#2,2"% 2,3"1/& One 'rgu(ent is +'lse) Result* FALS$

    Notes on t*e AND Function

      eturns ' if all its arguments are 'B returns F+ if one or more argument is F+.

      S+ntax& AND(logical,logical-, !!!)

    Re"a.s  'he arguments must evaluate to logical values such as ' or F+&

    or the arguments must %e arrays or references that contain logical values.

      /f an array or reference argument contains text or empty cells& those values are ignored.

      /f the specified range contains no logical values& - returns the ,0+5 error value.

      +ogicalA& logical?& ... are A to =2 conditions you #ant to test that can %e either ' or F+

  • 8/20/2019 Logic Functions Practice.xls

    8/33

    .

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    9/33

    AND, OR, NOT

    Data

    A1D

    E

    Fo"ula

    -(717& 71H7I)

    J(717& 71H7I)

    -J'(71

  • 8/20/2019 Logic Functions Practice.xls

    10/33

    Desci'tion (Result)

     /s A1 greater than D and less than EL esult: F+

     /s A1 greater than D or less than EL esult: '

     /s A1 plus D not e9ual to ?KL esult: F+

      t one or more conditions

    s.

      e true to return '.

    must %e true to return '.

    (' or F+) is reversed.

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    11/33

    The IF Function

    Data

    ./

    Fo"ula

     "IF#B.0"1//%itin 4udget%Over 4udget&

     "IF#B."1//%SUM#BigR'nge&%&

    Notes on t*e IF Function

    eturns one value if a condition you specify evaluates

    and another value if it evaluates to F+.

    se /F to conduct conditional tests on values and for

    S+ntax& IF(logical/test,%alue/if/tue,%alue/if/fa

    For example& A2A22 is a logical expressionB if the v

    the expression evaluates to '. Jther#ise& the exp

    'his argument can use any comparison calculation op

    if this argument is the text string "6ithin %udget" and

    evaluates to '& then the /F function displays the

    /f logicalMtest is ' and valueMifMtrue is %lan$& this

    'o display the #ord '& use the logical value '

    0alueMifMtrue can %e another formula.

     if this argument is the text string "Jver %udget" and

    evaluates to F+& then the /F function displays the

    /f logicalMtest is F+ and valueMifMfalse is omitted&

    Logical/test  is any value or expression that can %e

    #alue/if/tue  is the value that is returned if logical

    #alue/if/false  is the value that is returned if logica

  • 8/20/2019 Logic Functions Practice.xls

    12/33

    valueMifMtrue& there is no comma)& then the logical v

    /f logicalMtest is F+ and valueMifMfalse is %lan$ (th

    there is a comma follo#ed %y the closing parenthesis)

    is returned. 0alueMifMfalse can %e another formula.

    Re"a.s

    p to seven /F functions can %e nested as valueMifMtrue

    arguments to construct more ela%orate tests.

    6hen the valueMifMtrue and valueMifMfalse arguments a

    /F returns the value returned %y those statements.

      /f any of the arguments to /F are arrays& every eleme

    is evaluated #hen the /F statement is carried out.

  • 8/20/2019 Logic Functions Practice.xls

    13/33

    Desci'tion (Result)

    to '

    ulas.

    se)

    lue in cell A2 is e9ual to A22&

    ression evaluates to F+.

    erator.

      the logicalMtest argument

      text "6ithin %udget".

    argument returns 2 (Nero).

    for this argument.

    he logicalMtest argument

      text "Jver %udget".

    (that is& after

    I+ te v'lue in ell B. is less t'n or e5u'l to 1//% ten te+or(ul' dis6l'7s itin 4udget) Oter8ise% te +unctiondis6l'7s Over 4udget) Result* Over 4udget

     I+ te nu(4er '4ove is 1//% ten te r'nge n'(edBigR'nge is su((ed) Oter8ise% e(6t7 te9t #& is returned)Result* e(6t7 te9t

    evaluated to ' or F+.

     Mtest is '. For example&

    lMtest is F+. For example&

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    14/33

    lue F+ is returned.

    t is& after valueMifMtrue&

    & then the value 2 (Nero)

    and valueMifMfalse

    re evaluated&

    t of the array

  • 8/20/2019 Logic Functions Practice.xls

    15/33

    Nested IF Statements

    Scoe

    K1D2

    IE

    Fo"ula

      /F(71ED&""&/F(71ID&"7"& /F(71D&"C"&/F(711D&""&"F"))))

      /F(7ED&""&/F(7ID&"7"& /F(7D&"C"&/F(71D&""&"F"))))

      /F(7IED&""&/F(7IID&"7"& /F(7ID&"C"&/F(7I1D&""&"F"))))

    Notes&

      /n the examples a%ove& the second /F statement is also the valueMifMfalse

    argument to the first /F statement. imilarly& the third /F statement is the

      valueMifMfalse argument to the second /F statement. For example& if the

      first logicalMtest (verageED) is '& "" is returned. /f the first logicalMtes

    is F+& the second /F statement is evaluated& and so on.

    'he letter grades are assigned to num%ers using the follo#ing $ey.

    If Scoe is

    Greater than ED

    From E2 to ED

    From I2 to ID

    From 2 to D

    +ess than 2

  • 8/20/2019 Logic Functions Practice.xls

    16/33

    Desci'tion (Result)

    ssigns a letter grade to the first score (F).

    ssigns a letter grade to the second score ().

    ssigns a letter grade to the third score (C).

    T*en etun

    7

    C

    F

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    17/33

    Olive Oil Loic ! "

    Costgallon for the first 122 gallons: 0-1

    Costgallon for gallons a%ove 122: 0-2-um%er of gallons:

    2

    341

    522

    622

    Formulas to calculate the cost of:

    A2 gallons:  0 -12 /F(7IH122&CK*

    KE= gallons:  0 ,27 /F(7EH122&CK*

    122 gallons:  0 ,522 /F(7DH122&CK*

    A22 gallons:  0 11,522 /F(7A2H122&CK*

    Loic%ro&l

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    18/33

      I& 122*CK

  • 8/20/2019 Logic Functions Practice.xls

    19/33

    Olive Oil Loic ! (

    Costgallon for the first 122 gallons: 0-1

    Costgallon for the next 122 gallons: 0-2Costgallon for gallons A&222: 05

    -um%er of gallons:

    ,622

    341

    -22

    Formulas to calculate the cost of: Chec$:

    A22 gallons: 0 12,522 s*oul$ be

    KE= gallons:  0 ,27 s*oul$ be?22A gallons:  0 16,55 s*oul$ be

    Loic%ro&l

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    20/33

      12,522   /F(7EH122&7E*OCOK&/F(7EHA222&(122*OCOK)

  • 8/20/2019 Logic Functions Practice.xls

    21/33

    O1)

  • 8/20/2019 Logic Functions Practice.xls

    22/33

    Olive Oil Loic ! )

    4ore +ogic Practice #ith a ifferent +ayout.

    'he formulas here use 4/-& 4& a nested /F& and 4PJC'.

    622 341

    gallons gallons

    galsprice level galsprice level

    First 122 gallons at 0-1!22 122 KE=

    -ext 122 gallons at 0-2!22 122 2

    ny additional gallons at 05!22 22 2

    Cost:  0 12,522 0 ,27

    4/-(;OD& OOA?) 4/-(/OD& OOA?)

    4(/F(;ODHOOA?<OOA=& ;OD8OOA?&OOA=)& 2)

    4(/F(/ODHOOA?<OOA=& /OD8OOA?&OOA=)& 2)

    /F(;ODA222& ;OD8A222& 2)

    /F(/ODA222& /OD8A222& 2)

     8SUMPRODUCT(0F0-&0F03, 9-&93)

    8SUMPRODUCT(0F0-&0F03, I-&I3)

    Loic #sed $or the Olive Oil%ro&lem in the %ro$icienc

    Exercises

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    23/33

    -22

    gallons

    galsprice level

    122

    122

    A22A

     0 16,55

    4/-(QOD& OOA?)

    4(/F(QODHOOA?<OOA=& QOD8OOA?&OOA=)& 2)

    /F(QODA222& QOD8A222& 2)

     8SUMPRODUCT(0F0-&0F03, :-&:3)

  • 8/20/2019 Logic Functions Practice.xls

    24/33

    IF ! *udet exam+le

    Actual Ex'ensesOA&122

    O122

    Fo"ula

      /F(71C1&"Jver 7udget"&"JR")

      /F(7C&"Jver 7udget"&"JR")

  • 8/20/2019 Logic Functions Practice.xls

    25/33

    ;u$gete$ Ex'ensesOD22

    OD22

    Desci'tion (Result)

    Chec$s #hether the first ro# is over %udget. esult: Jver 7udget

    Chec$s #hether the second ro# is over %udget. esult: JR

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    26/33

    IF ith nested AND

    Data

    ./

    1/

    Fo"ula

    "AND#10B.% B.01//&

    Notes-

      In e'c +or(ul' '4ove 'n AND +unction

    nested inside 'n IF +unction) Te AND

      +unction serves 's te +irst 6'r'(eter o

    IF +unction) I+ te AND +unction ev'lu't

    TRU$% ten te 2nd IF +unction 6'r'(

    returned) I+ te AND +unction ev'lu'tes

    FALS$% ten te 3rd IF +unction 6'r'(

    returned)

    "IF#AND#10B:% B:01//&%B:% Tev'lue is out o+ r'nge)&

      "IF#AND#10B.% B.01//&% B.% Tev'lue is out o+ r'nge)&

  • 8/20/2019 Logic Functions Practice.xls

    27/33

    Desci'tion (Result)

    Te v'lue ./ is 4et8een 1 'nd 1//) Result* TRU$

    Dis6l'7s te v'lue ./ or dis6l'7s ' (ess'ge) Result* ./

    is

    + te

    s 's

    ter is

    's

    ter is

      Dis6l'7s te v'lue 1/ or dis6l'7s ' (ess'ge) Result* Tev'lue is out o+ r'nge)

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    28/33

    The S#.IF $unction

    Po'et+ #alue Co""issionOA22&222 OI&222

    O?22&222 OAK&222

    O=22&222 O?A&222

    OK22&222 O?E&222

    Fo"ula Desci'tion (Result)

      4/F(71:7E&"A2222"&C1:CE)

    Notes&

    S+ntax& SUMIF(ange,citeia,su"/ange)

      #ill %e added. For example& criteria can %e expressed as =?& "=?"& "=?"& "appl

    Re"a.s&'he cells in sumMrange are summed only if their corresponding cells in range match the

    /f sumMrange is omitted& the cells in range are summed.

    um commissions for property values overOA2&222. esult: O=&222.

      Range is the range of cells you #ant evaluated.

      Citeia is the criteria in the form of a num%er& expression& or text that defines #hich

    Su"/ange are the actual cells to sum.

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    29/33

    OAK&222

    O?A&222

    O?E&222

    061,222

    es".

      riteria.

    ells

  • 8/20/2019 Logic Functions Practice.xls

    30/33

    The CO#NTIF $unction

    Fuit Data

    apples

    oranges

    peaches

    apples

    Fo"ula

      CJ-'/F(71:7E&"apples")

      CJ-'/F(C1:CE&"11")

    Notes

      ounts te nu(4er o+ cells 8itin ' r'nge

    Sntax- CO#NTIF/rane,criteria0

      te9t t't de+ines 8ic cells 8ill 4e count

    criteri' c'n 4e e96ressed 's 32% 32% ;3

    Rane is te r'nge o+ cells +ro( 8ic 7o

    Criteria is te criteri' in te +or( o+ ' nu

  • 8/20/2019 Logic Functions Practice.xls

    31/33

    Nu"be Data

    E

    1K

    I1

    =?

    Desci'tion (Result)

    t't (eet te given criteri')

    d) For e9'(6le%

    2% '66les)

    Count the num%er of cells holding "apples" in the

    "Fruit ata" column a%ove. esult: ?

    Count the num%er of cells #ith a value 11 in the"-um%er ata" column a%ove. esult: ?

    u 8'nt to count cells)

    4er% e96ression% or

    Return to Contents

  • 8/20/2019 Logic Functions Practice.xls

    32/33

    S#.%ROD#CT

    = ?E

    A 1

    K I

    I

    D =

    Fo"ula Desci'tion (Result)

      4PJC'(71:CI& 1:I)

    Notes&

      Multi6lies corres6onding co(6onents in te given 'rr'7s% 'nd returns te su(

    Sntax- S#.%ROD#CT/arra",arra(,arra), 1110

    Remar2s-

    Te 'rr'7 'rgu(ents (ust 've te s'(e di(ensions) I+ te7 do not% SUM!R

    error v'lue) SUM!RODUT tre'ts 'rr'7 entries t't 're not nu(eric

    Aa+ Aa+ -

     4ultiplies the components of thet#o arrays and sums the products Sthat is& =*? < E* < A*1 < K*I < *I <D*=. esult: A1

      Arr'71% 'rr'72% 'rr'73% ))) 're 2 to 3/ 'rr'7s 8ose co(6onents 7ou 8'nt to

    Return to Cont

  • 8/20/2019 Logic Functions Practice.xls

    33/33

    o+ tose 6roducts)

    DUT returns te

    's i+ te7 8ere ?eros)

    (ulti6l7 'nd ten 'dd)

      nts