Results 1 to 4 of 4
  1. #1
    daltonmillion is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    3

    Help Please! Calculation in query

    I am wanting to add a Field named [Token] in a query that takes the hourly sum of another field named [Amount]



    I have amount time stamped at the user's entry, and I am looking to do a If Statement in [Token] that if the hourly sum of [Amount] is zero then it adds a 1 to [Token] and a timestamp in the corresponding hour.

    Ex.

    From 9:00am - 9:59am (hour 9)
    Sum([Amount]) = 0
    therefore,
    [Token] = 1 @ hour 9

    Essentially i'm just trying to account for every hour, so if anyone has any ideas im open to suggestions. I'm just very novice at this and know next to no syntax for Access.
    Last edited by June7; 04-30-2015 at 12:23 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I use 2 queries,
    Q1 :select sum([amount]) as Total, [name], [hour]

    Q2: select * , iif([total]=0,1,[total]) as Token from Q1

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I was thinking something like this (untested):

    SELECT Hour(TimeField) As TheHour, Sum([Amount]) As TheAmount, IIf(Sum([Amount]) = 0, 1, 0) As TheToken
    FROM TableName
    GROUP BY Hour(TimeField)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    daltonmillion is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    I use 2 queries,
    Q1 :select sum([amount]) as Total, [name], [hour]

    Q2: select * , iif([total]=0,1,[total]) as Token from Q1
    This worked! Thank you very much

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

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