google-sheetssumgoogle-sheets-formulaarray-formulas

Arrayformula to SUM matching ID AND when date is between two dates


SUMIFS and/or QUERY inside ARRAYFORMULA

The problem explained above is a simpler, but very close approximation of what I'm trying to do. I'm looking to split up the 12 month year into 24 segments, the first and second part of each month. So essentially its identical to the issue above, except instead of specifying a month, I want to specify instead a range of dates that I can specify. I don't need exactly 24 segments, but for what I'm doing that visually is much better than 12 months. WEEKNUM() is an option, but that splits the year into 52 segments, which is far too many.

Here is an sheet example using slightly modified example data from the example above: https://docs.google.com/spreadsheets/d/1z90lA0DvsnURE2wYgbcXZY9_QRtG42ifV__QSMIrl5Y/edit?gid=646558234#gid=646558234

The other solution was =arrayformula(SUMIF(D3:D20&MONTH(F3:F20); A2:A7&2; E3:E20)) I've tried with DATEVALUE() and that works for single days, but I haven't been able to get anything to work when needing to specify a range. Perhaps DAYS() could be used to compare the date in the data vs the start of the month date, but that still encompasses a range of values 1-15 as opposed to a single value like the answer above. I'm not sure where to go from here.

Below is a link to the actual dataset. Check out cell BZ2 in the tab entitled List where I put the formula =map($A$2:$A,lambda(Σ,map(BZ1:CW1,lambda(Λ,let(x,sumifs('Ref4'!$Q$2:$Q,'Ref4'!$G$2:$G,Σ,'Ref4'!$P$2:$P,">="&Λ,'Ref4'!$P$2:$P,"<"&if(day(Λ)=1,offset(Λ,,1),eomonth(Λ,))),if(x=0,,x))))))

https://docs.google.com/spreadsheets/d/1k6nyu3xh0sLvbWjJ_vValAklzeTy72fvv3Cp0pEo--Y/edit?usp=sharing


Solution

  • You may try this single formula in Cell_L2:

    =map(K2:K6;lambda(Σ;map(L1:AI1;lambda(Λ;let(x;sumifs(E:E;D:D;Σ;F:F;">="&Λ;F:F;"<"&if(day(Λ)=1;offset(Λ;;1);eomonth(Λ;)));if(x=0;;x))))))
    

    enter image description here

    Updated formula:

    =map(A2:index(A:A,match(,0/(A:A<>""))),lambda(Σ,if(Σ="",,map(BZ1:CW1,lambda(Λ,let(x,index(sumifs('Ref4'!Q:Q,'Ref4'!G:G,Σ,--'Ref4'!P:P,">="&Λ,--'Ref4'!P:P,"<"&if(day(Λ)=1,offset(Λ,,1),eomonth(Λ,)))),if(x=0,,x)))))))
    

    enter image description here