Reputation: 71
im trying to figure out how can i use an arrayformula + SUMIFS when working with dates
Here is a demo sheet
https://docs.google.com/spreadsheets/d/1ttoA9EfMdYJHolcRVrLfpDA2GqYtt19gJruDogzGSf8/edit?usp=sharing
what i need :
in column O I need the balance overdue by client when the date of the payment < today() I need an arrayformula since is a very big data set
trying to use arrayformula + sumifs does not expand
trying to use arrayformula + sumif and using the & symbol is not working maybe because I need only when is < today ()
={"overdue";ARRAYFORMULA(IF(LEN(A2:A), (SUMIF(R:R&A:A,Q:Q&"<"&TODAY(),V:V))-M2:M ,))}
im looking for an alternative to this, any help will be very much apreciatted
Thank you !
Upvotes: 1
Views: 1172
Reputation: 34180
I think you just have to subtract clients who are earlier alphabetically and client/dates which are later alphabetically from the total, still using sumif:
=ArrayFormula(if(A2:A="",,sum(V2:V)-sumif(R2:R,"<"&A2:A,V2:V)-sumif(R2:R&Q2:Q,">"&A2:A&today(),V2:V)-M2:M))
Upvotes: 0
Reputation: 18708
I need an arrayformula since is a very big data set
The mmult()
function will error out when the dataset exceeds 3162 rows. To avoid that, use vlookup()
and query()
, like this:
=arrayformula(
{
"Overdue";
iferror(
vlookup(
A2:A,
query(
Q2:V,
"select R, sum(V)
where Q <= date" & text(today(), " 'yyyy-MM-dd' ") & "
group by R",
0
),
2, false
)
- M2:M
)
}
)
See the doubleunary sheet.
Upvotes: 1
Reputation: 9345
I've added a new sheet ("Erik Help") to your sample spreadsheet. The following array formula is in O2:
=ArrayFormula({"Overdue"; IF(A2:A="",, MMULT( TRANSPOSE(U2:U) * (TRANSPOSE(Q2:Q)=A2:A) * (TRANSPOSE(P2:P)<=TODAY() ),SEQUENCE( ROWS(U2:U), 1, 1, 0)) - M2:M)})
A virtual array is formed between the curly brackets { }.
The header is set first (which can be changed within the formula as you like).
If any cell in A2:A is null, then the corresponding cell in O2:O will also be null.
MMULT
performs M
atric MULT
iplication. Here, I've used it to multiply a TRANSPOSE
d version of the amounts in U2:U by two TRANSPOSE
d conditional statements (each of which will result to a 1 of TRUE or a 0 if FALSE). If both statements are TRUE, then the value from U2:U will remain (i.e., X * 1 * 1); but if either statement is FALSE, then the result for that row of U2:U will be 0 (e.g., X * 0 * 1 -or- X * 1 * 0 -or- X * 0 * 0).
The conditional statements check 1.) to see if the client name is the same as the current row; and 2.) to see if the date is less than or equal to TODAY().
It is important that these three readings be TRANSPOSE
d, in order to form a 2D virtual grid.
The remaining values after the above process will be in virtual horizontal rows parallel to each actual row. These form the first matrix.
The second matrix is formed with SEQUENCE
and is simply a stack of the number 1 as tall as the number of rows from A2:A in the sheet.
Since anything times 1 is the original number, all 0 or value results from the first matrix are returned and then added (which is the function of MMULT
).
From this, the value in M2:M can be subtracted.
Upvotes: 0