Results 1 to 8 of 8
  1. #1
    wichitawx is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    2

    table to calculate past information with current?

    Hi


    I'm looking to create a column that will do some calculation, but it will need to compare it with some past data is this possible?
    specifically I need to choose which is the bigger value. here is the formula that I would use in excel (see attached photo of what I'm looking for)

    =MAX(value2 - value3, value2-(prior day Value4), (prior day Value4) - value 3)

    Click image for larger version. 

Name:	screenshot--2018-04-27-21-40-20.png 
Views:	18 
Size:	9.3 KB 
ID:	33776
    (sorry in the photo it should NOT be value 1 - value 2 .... but instead value 2 - value 3)

    Is this possible to do in Access?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'm not sure I follow. For the first record, there is no prior day so any portion that involves a "prior day" before 1/12/01 would result in Null. Therefore 46-43 would be the only calculation. Looking at the second record, the calculation would be Max of 50-45, 50-44, 44-45; the answer being 6. What you probably need to look at is subqueries, though this one would be somewhat complex, methinks.

    Almost always a code solution is also possible. If you wanted only the short answer, I should have just said "yes".
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,681
    On fly:
    Code:
    =MAX(value2 - value3, (value2-DLookup("Value4","YourTable","Date = #" & DMax("Date","YourTable", "Date < #" & [Date] & "#" ) & "#")), (DLookup("Value4","YourTable","Date = #" & DMax("Date","YourTable", "Date < #" & [Date] & "#" ) & "#") - value 3))
    


    But probably this returns error for 1st row too as Micron mentioned. Without Access available at weekend, I haven't tools to check the formula and possible workarounds.

    And probably the best solution will be an UDF designed specially for this case - there you can have solution for 1st row exactly in a manner you want.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you also need to define the relationship with past data - the previous day? what if there is a gap between yesterday and today? what if there are two records today and/or yesterday?

  5. #5
    wichitawx is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    2
    Thanks everyone for your quick response
    @micron the first data I would skip doing the max calculation. And start on the 2nd data.

    @arvilLaanemets, thanks I'll try that out. I'm relatively a newbie with access, but will research and look into UDF.

    @ajax, I'm only entering data once a day, there will be days that there is no data (like holidays) and I would skip entering data for those days and only continue on days there is data.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    In that case a sub query is the way to go rather than a domain function. The subquery Would be something like

    (Select top 1 myfield from mytable T where mydate<mytable.mydate order by mydate desc) as prevvalue

    Note the T alias

    Sent from iPhone so please excuse typos

  7. #7
    Dehn0045 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    11
    You will find that things that are super easy in Excel become quite difficult in Access. Remember that in Access the location of the record in the table is usually not meaningful. Assume that the records in your table are in a totally random order and then write your code accordingly. Avoiding bugs can be difficult. For example, what if there are multiple records with the same date, what if somebody puts in a future date, or enters the wrong year on a record...

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Assume that the records in your table are in a totally random order
    This can usually be overcome by basing something (form, report, recordset, query, etc.) on an ordered query instead of a table. A query can impose a logical order as long as the fields providing the Order By are suitable.

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

Similar Threads

  1. How to calculate # of months past a date?
    By djclinton15 in forum Queries
    Replies: 8
    Last Post: 02-05-2017, 03:48 PM
  2. Replies: 19
    Last Post: 01-24-2016, 07:48 PM
  3. Variation of past and current sales
    By v!ctor in forum Access
    Replies: 2
    Last Post: 03-16-2013, 09:06 AM
  4. How to calculate current balance on hand
    By fazly lee in forum Access
    Replies: 11
    Last Post: 09-05-2012, 09:16 PM
  5. Replies: 2
    Last Post: 10-08-2011, 06:33 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