Results 1 to 4 of 4
  1. #1
    lostmySQL is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    1

    Help: Query in which rows grow and reference previous rows to calculate rate increase

    Basically I am trying to create a query that would dynamically grow based on another table of of labor positions and would also forecast their yearly increase. I want to avoid having to create new columns and calculations for every new year.


    Data: Table 1: LCAT

    LCAT Base Wage
    General Worker $4.00
    General Admin $5.00



    Data: Table 2: Escalation Rate

    Year Escalation
    Year 1 0%
    Year 2 4%
    Year 3 4%

    Desired Query Result:

    LCAT Year Annual Rate
    General Worker Year 1 $4.00
    General Worker Year 2 (4.00 * (1+4%) = $4.16
    General Worker Year 3 (4.16 * (1+4%) = $4.33
    General Admin Year 1 $5.00
    General Admin Year 2 (5.00 * (1+4%) = $5.20
    General Admin Year 3 etc...

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,423
    not quite the format you wanted but something like this is a way that could work

    Code:
    SELECT Table1.LCAT, [BaseRate]*[YR1] AS ar1, [BaseRate]*[YR2] AS ar2, [BaseRate]*[YR3] AS ar3
    FROM (SELECT 1+[y1].[escalation] AS yr1, [yr1]*(1+[y2].[escalation]) AS yr2, [yr2]*(1+[y3].[escalation]) AS yr3
    FROM Table2 AS y1, Table2 AS y2, Table2 AS y3
    WHERE (((y1.Yr)=1) AND ((y3.Yr)=3) AND ((y2.Yr)=2)))  AS E, Table1;
    LCAT ar1 ar2 ar3
    worker 4 4.16 4.3264
    admin 5 5.2 5.408

    you can use a union query to get it into the vertical format

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Queries pulling from multiple tables and don't have JOIN clause invoke Cartesian relationship - every record of each table associates with every record of other table. This type of query can perform slowly with large dataset. If query performs so slowly to be non-functional, should probably create records for each year.
    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.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Looks like your question is related to this earlier one, might want to have a look at the sample:
    https://www.accessforums.net/showthr...148#post493148

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 5
    Last Post: 06-19-2019, 01:04 PM
  2. Replies: 35
    Last Post: 12-12-2018, 11:18 PM
  3. Replies: 10
    Last Post: 02-14-2018, 06:21 AM
  4. Replies: 22
    Last Post: 12-20-2015, 02:46 AM
  5. Replies: 0
    Last Post: 02-09-2012, 05:43 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