Results 1 to 8 of 8
  1. #1
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8

    Applying a "Floor" of Zero to Query Results


    How can I apply a "floor" of zero to the result of a query? For example, I have a field which takes the difference between 2 fields (from another query) & returns negative numbers, positive numbers, and 0's. I would like the negative results that are returned to simply be 0. Thanks for the help!

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    use the iif function

    iif(result<=0,0,result)

  3. #3
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8
    Is there any other way besides using iif? My database is already crazy slow because I have about 8 other iff's within my queries & I'm dealing with hundreds of thousands of rows of data on my tables. If that's the only way I'll roll with it, but just thought I'd ask...

    Also, thanks for the quick reply!

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    not really that will be 'quicker'

    you could try the choose function

    choose((result<0)+2,result,0) or choose(abs(result<0)+1,0,result)

    If you are using nested iifs, try the switch function which is a bit like a case statement

  5. #5
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    just a thought, if you are using iif's to detect nulls, try using the nz function

    so instead of iif(value is null,0,value)

    use

    nz(value,0)

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In place of IIF(), could also use

    result * ((result >= 0) * -1)

    or

    result * Abs(result >= 0)

  7. #7
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    result * Abs(result >= 0)
    like that one ssanfu

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Re: use of IIf() and Nz() in query http://allenbrowne.com/QueryPerfIssue.html

    Why do substitution in query? Why not expression in textbox on form or report?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  2. Replies: 1
    Last Post: 05-20-2015, 09:53 AM
  3. Replies: 2
    Last Post: 09-09-2014, 12:50 PM
  4. Replies: 8
    Last Post: 06-12-2014, 09:55 AM
  5. Replies: 4
    Last Post: 03-23-2012, 01:18 PM

Tags for this Thread

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