In Google Sheets I have employees' expense data.
Each sheet contains data for multiple employees, for a single month.
In a main sheet I have a formula that returns the SUM of all expenses for a single employee across all months (sheets).
Current Formula
=SUM(
IFNA(filter('Oct. Expenses'!$D$4:$D$100, regexmatch('Oct. Expenses'!$C$4:$C$100, F9)),0),
IFNA(filter('Nov. Expenses'!$D$4:$D$100, regexmatch('Nov. Expenses'!$C$4:$C$100, F9)),0),
IFNA(filter('Dec. Expenses'!$D$4:$D$100, regexmatch('Dec. Expenses'!$C$4:$C$100, F9)),0),
IFNA(filter('Jan. Expenses'!$D$4:$D$100, regexmatch('Jan. Expenses'!$C$4:$C$100, F9)),0),
IFNA(filter('Feb. Expenses'!$D$4:$D$100, regexmatch('Feb. Expenses'!$C$4:$C$100, F9)),0))
This formula and variations are used in multiple places. The current approach works but is cumbersome because each time a new monthly sheet is added, all formulas must be manually edited to include it.
I want to make this formula dynamic by listing the sheet names in column L
and passing them to the formula.
In that way I can simply add a new sheet name to that column and all the formulas will update accordingly.
I tried the following formula but it only works for a single sheet name, not the list of sheets in L1:12
.
What am I missing?
=SUM(
ARRAYFORMULA(
FILTER(
INDIRECT(L1&"!$D$4:$D$100"),
REGEXMATCH(INDIRECT(L1&"!$C$4:$C$100"), $F$9))))
Sample Monthly Expenses Sheet
A | B | |
---|---|---|
3 | Employee | Amount |
4 | Doe A'Deer | $5. 28 |
5 | Down Town | $5. 39 |
6 | Sally Field | $4. 02 |
7 | GI Joe | $12. 00 |
8 | Doe A'Deer | $8. 59 |
9 | GI Joe | $14. 67 |
10 | Doe A'Deer | $9. 97 |
11 | Down Town | $10. 87 |
12 | Jane Doe | $10. 68 |
13 | Down Town | $9. 06 |
14 | GI Joe | $8. 98 |
15 | Doe A'Deer | $13. 31 |
16 | Down Town | $12. 24 |