Search code examples
excelexcel-formulasumsumifs

Excel SUM based on dynamic range


I have below data in excel.

Product Room 09/13/2021 09/12/2021 09/11/2021 08/10/2021 08/09/2021 08/08/2021 08/07/2021
A White 1 1 2 4 2 1 1
A Black 2 5 6 7 5 5 6
B White 3 9 1 1 6 9 1
B Black 4 3 4 4 1 1 4
C White 5 4 7 6 4 4 7
C Black 6 6 6 7 7 1 4

I want to see if there is a good way to replace Formula with excel formulas. enter image description here

Where:

Formula 1 = Sum of last three days (first three columns so columns C, D, E) for Product= A and Room = White. Which is sum of cell C2+D2+E2 = 1+1+2 = 4

Formula 2 = Sum of values where Month of Date is 8 in row 1 and for Product = A and Room = White. Which is sum of cell F2+G2+H2+I2 = 4+2+1+1 = 8

I tried using =SUMPRODUCT() with VLOOKUP =SUMPRODUCT(VLOOKUP(C6,B12:F18,{3,4,5},0)) from this link but how can I dynamically pick the array of columns.


Solution

  • This will get your first request. Use Evaluate Formulas to understand how it works, see if you can apply it to your other needs.

    =SUMPRODUCT((C2:I7)*(A2:A7="A")*(B2:B7="White")*(C1:I1>TODAY()-3))