Results 1 to 11 of 11
  1. #1
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11

    Access 2010 Query Using IIF Function

    All,



    Im after some help regarding a query problem i have

    Please have a look at the attached pic DD2,

    The result of running the query is shown in attched pic DD3

    Basically what i need is for total2 to return a value of 2 or 0
    If the value of total is greater that 6.1 it needs to return 2 if its less that 6.1 it needs to return 0

    Many thanks in advance


    Steve
    Attached Thumbnails Attached Thumbnails DD2.jpg   DD3.jpg  

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The results picture isn't attached. What you have will sum that calculation. If you mean you want that result for the sum of total for each team, try reversing your functions:

    IIf(Sum(Total) > 6.1, 2, 0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11
    Pbaldy,

    ive tried the above and it come with a syntax error

    i have also tried
    Total2:IIF(Sum[Total] > 6.1, 2, 0))
    Total2:IIF(Sum[Total])>6.1,2,0)

    which both of these comes up with syntax errror on the [Total]

    In Excel the equivalent is =IF(SUM(A1:A5)>6.1,2,0) where A1:A5 is total and this works so i dont know what is wrong
    its probably staring me in the face but i just cant see it

    Best Regards


    Steve

  4. #4
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11
    Original Pictures

    Click image for larger version. 

Name:	DD2.jpg 
Views:	7 
Size:	16.9 KB 
ID:	24695

    Click image for larger version. 

Name:	DD3.jpg 
Views:	8 
Size:	14.2 KB 
ID:	24696

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Sorry, I had an extra parentheses in there. Try

    IIf(Sum(Total) > 6.1, 2, 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11
    Pbaldy

    PBaldy


    Brilliant it works ........... thank You very much

    Taking it a step further in another query

    how do i do the same as the above but

    Values above 6.1 return the value of 2
    Values equal to 6 return the value of 1
    Values less that 5.9 return the value of 0


    Many Thanks


    Steve

  7. #7
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11
    PBaldy

    Ive tried the following Nested IIF's and none of them work

    IIf(Sum(Total) > 6.1,2,
    (Sum(Total) = 6,1,0)

    IIf(Sum([Total])>6.1,2,(Sum([Total])=6,1,0)

    IIf(Sum([Total])>6.1,2,(Sum([Total])=6,1,0),0)

    IIf(Sum([Total])>6.1,2,IIF(Sum([Total]=6,2,0),0)


    Any Ideas


    Many Thanks


    Steve

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Try

    IIf(Sum([Total])>6.1,2,IIF(Sum([Total])=6,1,0))

    Note there's a flaw in your logic that leaves between 6 and 6.1 out. I would suspect you want:

    IIf(Sum([Total])>6,2,IIF(Sum([Total])=6,1,0))

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    pinkpanther6666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    11
    Many Many thanks for your help

    Just for Info : The only returned values i get for Total are whole numbers ranging between 0 and 12

    Values 0 to 5 get Nil Points
    Value 6 gets 1 Point
    Value 7 to 12 get 2 points

    Many thanks again


    Steve
    Last edited by pinkpanther6666; 05-23-2016 at 03:10 PM. Reason: Solved

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Nested IIFs are treacherous to maintain.
    For smaller data sets where performance is not an issue, the SWITCH function may be a better option.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Vlookup Function in MS Access 2010
    By pabbydf in forum Misc
    Replies: 4
    Last Post: 01-09-2014, 07:52 PM
  2. Replies: 5
    Last Post: 05-22-2013, 12:20 PM
  3. Need Help With DLookUp Function in Access 2010
    By fmartz in forum Programming
    Replies: 2
    Last Post: 09-05-2012, 09:34 AM
  4. Creating Browse function in Access 2010
    By martindenise in forum Access
    Replies: 3
    Last Post: 08-09-2012, 05:44 PM
  5. Access 2010 function
    By abm1961 in forum Access
    Replies: 5
    Last Post: 07-21-2011, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums