Access get value from previous record

后端 未结 4 1514
你的背包
你的背包 2021-01-25 20:46

I have an Access query with the following

GL_A.Account, 
GL_P.FiscalYear, 
GL_P.FiscalPeriod, 
GL_P.BeginningBalance, 
GL_P.DebitAmount, 
GL_P.CreditAmount, 
[B         


        
4条回答
  •  孤独总比滥情好
    2021-01-25 21:19

    See if this helps. Put a 2nd copy of the table in the query, joined to the 1st copy on Account and FiscalYear but not on FiscalPeriod. Then the ActualBeginningBalance can be calculated from the 2nd copy of the table with a constraint to select only FiscalPeriod < the FiscalPeriod from the 1st table. Note - you may get a null results for January, which you may need to convert to a 0.

    OK, it's a bit more complicated - I did end up using a subquery similar to the other response, but calculated the EB instead of trying to pull it from the table

    SELECT Ledger.Account, Ledger.FiscalYear, Ledger.FiscalPeriod, 
    [BeginningBalance]+
           IIf([FiscalPeriod]<>"01",
                 (select sum(T.BeginningBalance+T.DebitAmount-T.CreditAmount) 
                 from Ledger T 
                  where T.account=Ledger.account and T.FiscalYear=Ledger.FiscalYear and T.FiscalPeriod

提交回复
热议问题