简体   繁体   中英

How do you use an array formula to calculate a running total that decreases as you move up rows?

When an employee works overtime for a client, we allocate those hours to the client's most recent shift (farthest row down for that employee), and then allocate the remaining OT up the rows. Column D lists total hours to allocate. Column E is a formula for OT hours available; I am trying to convert Col E to an array, but am running into a circular dependency error:

Formula that works

=IF(D2>0,D2,E3-C3)

Array formula that results in a circular dependency error:

=ARRAYFORMULA(IF(D2:D>0,D2:D,E3:E-C3:C))

I do not want to enable iterative calculations, as my sheet is about two thousand rows. I have read cumulative sum posts that incorporate MMULT and ROW, or SUMIF and ROW into the ARRAYFORMULA function, but I cannot figure out how to cumulatively decrease a number as it moves up rows.

在此处输入图片说明

Here is a link to the sheet Thank you.

I made a new tab called MK.Help and put this formula in E2. If i understand what you're going for, i think it'll work?

=ARRAYFORMULA(MMULT(N(A2:A=TRANSPOSE(A2:A))*(ROW(B2:B)<=TRANSPOSE(ROW(B2:B))),D2:D-C2:C)+C2:C)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM