I'm trying to use a SUMIFS formula with conditions that include an or which relies on a cell reference.
I've solved every partial solution to this I can think of but still can't get something that works for the final result.
The expected solution would be:
=sumifs(A:A,B:B,{"x","y"})
where A:A is summed if the value in B is either "x" or "y" (this is an MCVE, the real situation requires multiple conditions including a date comparison, see below)
For literal values, this is a solution:
=ArrayFormula(sumifs(A:A,regexmatch(B:B,"x|y"),TRUE))
Using SUMIF (but not SUMIFS), this works:
=sum(arrayformula(sumif(B:B,{E2,"y"},A:A)))
Multiple SUMIFS work but the number of addends grow exponentially with additional conditions:
=sumifs(A:A,B:B,E2)+sumifs(A:A,B:B,E3)
The following two formulae work in Excel but not Google Sheets:
=SUM(SUMIFS(A:A,B:B,{"x","y"}))
=SUM(SUMIFS(A:A,B:B,E2:E3))
MCVE sheet: https://docs.google.com/spreadsheets/d/11q9RXEr84WuyuAXXmGwkGSdwaKznXD0IyGj187XYp1I/edit
This is the current state of the real formula in cell C78 on the current sheet
=(sumifs('Sheet2'!$C:$C,'Sheet2'!$B:$B,$A78,'Sheet2'!$D:$D,">="&C$1,'Sheet2'!$D:$D,"<"&D$1)
+ArrayFormula(sumifs('Sheet2'!$I:$I,regexmatch('Sheet2'!$J:$J,"CAD|^$"),TRUE,'Sheet2'!$H:$H,$A78,'Sheet2'!$K:$K,"<"&D$1,'Sheet2'!$L:$L, ">"&C$1))
+ArrayFormula(sumifs('Sheet2'!$I:$I,regexmatch('Sheet2'!$J:$J,"CAD|^$"),TRUE,'Sheet2'!$H:$H,$A78,'Sheet2'!$K:$K,"<"&D$1,'Sheet2'!$L:$L, "="))
+sumifs('Sheet2'!$I:$I,'Sheet2'!$J:$J,"USD",'Sheet2'!$H:$H,$A78,'Sheet2'!$K:$K,"<"&D$1,'Sheet2'!$L:$L, ">"&C$1)*C$110
+sumifs('Sheet2'!$I:$I,'Sheet2'!$J:$J,"USD",'Sheet2'!$H:$H,$A78,'Sheet2'!$K:$K,"<"&D$1,'Sheet2'!$L:$L, "=")*C$110)
*if(C$1 > TODAY(), 0, 1)
where the current sheet has monthly dates in row 1, categories in col A, and monthly exchange rate in row 110.
Explanation: Add the following 5 items
- One time expenses in the current month
- Recurring expenses in CAD or blank currency that existed in this month and haven't ended yet
- Recurring expenses in CAD or blank currency that existed in this month and are perpetual
- Recurring expenses in USD currency that existed in this month and haven't ended yet (multiplied by FX rate)
- Recurring expenses in USD currency that existed in this month and are perpetual (multiplied by FX rate)
I'm trying to at least combine items 2+3 and 4+5 (if not 2-5 completely)
Sheet2 has 2 parts:
- One-Time items with categories in col B, values in col C, dates in col D
- Recurring items with categories in col H, values in col I, currency in col J (which represents CAD when blank), start date in col K, and end date in col L (which represents perpetual when blank)