Maths noob
Maths noob

Reputation: 1802

array formula: sum to date

I have a number of invoices:

invoice # start end paid on amount paid to date (hardcoded)
1 01/01/2020 30/01/2020 01/02/2020 £10.00 £10.10
2 01/02/2020 20/02/2020 01/03/2020 £7.50 £17.60
3 21/02/2020 30/02/2020 01/03/2020 £2.50 £20.10
4 01/01/2000 30/01/2000 01/03/2000 £0.10 £0.10

Where the invoices

I want to add a field called paid to date that would show me the amount I have been paid so far where it would add the amount for:

Effectively mirroring the hard-coded column.

This is how I do it with a query (which might not be the simplest/most elegant way of doing it)

=Index(
    query(
      A1:E10, 
      "select SUM(E)
      where D is not null
      and (
        D < date '"& TEXT( D2,"yyyy-mm-dd")&"' 
        OR (
          D = date '"& TEXT( D2,"yyyy-mm-dd")&"'
          and
          B <= date '"& TEXT( B2,"yyyy-mm-dd")&"'
        )
      )"
    ),
    2, 1
  )

which is all well and good. but I want to be able to do it with array-formula, so I can have it auto-generated for me.

I tried using it inside array-formula but the value is only ever generated for the first row. I guess it's misinterpreting the range I am passing as the range of the query function, ie A1:E10. is there an easy way of fixing it?

Do I need to use VLookup?

Here is a sample spreadsheet.

Upvotes: 0

Views: 145

Answers (2)

Ron Rosenfeld
Ron Rosenfeld

Reputation: 60174

If you have Excel 365, you can Filter directly.
Note that I am using a table with structured references. Then you don't need to adjust the range references as you add/remove rows from the table.

=SUM(FILTER([amount],([paid on]<[@[paid on]])+(([paid on]=[@[paid on]])*([start]<[@start])),0),[@amount])

This part does the filtering:

...([paid on]<[@[paid on]])+(([paid on]=[@[paid on]])*([start]<[@start]))...

enter image description here

Note: You can use the same algorithm in Sheets:
Note that I am using regular addressing, and also using a semicolon instead of a comma for the argument separators

=sum(iferror(FILTER($E$2:$E$5;($D$2:$D$5<$D2)+(($D$2:$D$5=$D2)*($B$2:$B$5<$B2)));0);E2)

Upvotes: 0

player0
player0

Reputation: 1

try:

=INDEX(IFNA(VLOOKUP(A2:A, {INDEX(SORT({A2:B, D2:E}, 2, 1, 3, 1),,1), 
 MMULT(TRANSPOSE((ROW(E2:E)<=TRANSPOSE(ROW(E2:E)))*
 INDEX(SORT({A2:B, D2:E}, 2, 1, 3, 1),,4)), SIGN(E2:E))}, 2, 0)))

enter image description here

Upvotes: 1

Related Questions