How to create a row-by-row running total for a dynamic array?
Hello everyone,
I'm trying to create a single, dynamic formula that calculates a running total along each row. Each row's running total needs to start with a specific initial value from that same row.
Here is a simplified version of my data and the desired result.
Requirements table
| Material | D 2026-02-05 | D 2026-02-06 | D 2026-02-07 | D 2026-02-08 | D 2026-02-09 |
|---|---|---|---|---|---|
| 123 | -265 | -684 | -734 | -553 | -501 |
| 234 | -953 | -771 | -241 | -266 | -697 |
| 345 | -175 | -247 | -516 | -795 | -762 |
| 456 | -655 | -635 | -456 | -196 | -502 |
| 567 | -192 | -708 | -492 | -471 | -273 |
| 678 | -448 | -567 | -636 | -712 | -289 |
| 789 | -224 | -358 | -967 | -996 | -876 |
Table formatting by ExcelToReddit
Relevant materials table
| Material | Current Inventory | D 2026-02-05 | D 2026-02-06 | D 2026-02-07 | D 2026-02-08 | D 2026-02-09 |
|---|---|---|---|---|---|---|
| 123 | 485 | |||||
| 234 | 141 | |||||
| 345 | 430 | |||||
| 456 | 415 |
Desired solution
| Material | Current Inventory | D 2026-02-05 | D 2026-02-06 | D 2026-02-07 | D 2026-02-08 | D 2026-02-09 |
|---|---|---|---|---|---|---|
| 123 | 485 | 220 | -464 | -1198 | -1751 | -2252 |
| 345 | 141 | -34 | -281 | -797 | -1592 | -2354 |
| 567 | 430 | 238 | -470 | -962 | -1433 | -1706 |
| 789 | 415 | 191 | -167 | -1134 | -2130 | -3006 |
Table formatting by ExcelToReddit
I've tried several advanced array formulas but keep hitting roadblocks:
- SCAN: This works perfectly for a single hardcoded row
=SCAN(B2,J2:N2,LAMBDA(a,b,a+b))), but isn't dynamic. - BYROW: When I try to make it dynamic
=BYROW(SCAN(B2,J2:N2,LAMBDA(a,b,a+b)))), it fails with a #CALC error because BYROW's LAMBDA expects a single value, but SCAN returns a whole array for each row so, nested arrays error. - MAKEARRAY: This feels like the right tool. My first attempt correctly looked up the data but didn't accumulate the total; it just added the starting inventory to each day's value individually.
=LET( materials,A2:A5, startValues,B2:B5, relevantData,INDEX(J2:N8,XMATCH(A2:A5,I2:I8),XMATCH(C1:G1,J1:N1)), result,MAKEARRAY(ROWS(relevantData),COLUMNS(relevantData),LAMBDA(r,c,INDEX(startValues,r)+INDEX(relevantData,r,c))), result) My final attempt was to create a running sum inside the MAKEARRAY, but it failed with a #VALUE! error. I now understand this is because my syntax for creating the range to SUM was incorrect SUM(INDEX(relevantData,r,c):c).
I'd appreciate your help
[link] [comments]
Want to read more?
Check out the full article on the original site