Hey guys. I have sample data from an order management system below. INV means an invoice, so the balance goes up. PY means a payment, so the balance goes down. And CM means Credit Memo, which also means the balance goes down. However, for our purposes, we need to look at the group of clearing numbers separately, which is causing issues.
Type Clearing Number Amount document_date
PY 2151885 -30 5/10/2010
INV 2151886 100 5/4/2010
INV 2151886 100 5/5/2010
PY 2151886 -50 5/6/2010
CM 2151886 -50 5/6/2010
PY 2151886 -100 5/10/2010
PY 2151887 -673.64 5/10/2010
PY 2151888 -7060 5/10/2010
The way the system works, within each CLEARING GROUP (as identified by the clearing numbers), each payment (PY) will be "applied" to the earliest open invoice, and close it out.
For example let's focus only on clearing #..886, first comes an invoice of 100, then comes another invoice of 100. The rules are that each time we have a Payment or Credit Memo, we apply (subtract) it to the EARLIEST OPEN invoice. Therefore, in this example, the first payment (PY) should close out 50 of the first invoice, leaving a remaining balance of 50. Then, the Credit Memo, (CM) should close the remainder of that first invoice. Finally, the last PY within the group should close the SECOND invoice.
The goal is to get the time between the credit memo, and the invoice it was applied to. I know this can be done in SQL via a loop function, but I am not so familiar with the language.
I have created many columns with IF statements, including a net running balance, but have not yet figured out how I would correctly calculate the time between each credit memo and early open invoice, within the clearing group.
I figure a vlookup may work, with conditions set that the invoice needs to be open. However, I would then need to run another column which would effectively close the next invoice per group. Keep in mind that there are many rows to the spreadsheet, and the groups may have as many as 10 credit memos in them.
Any help at all, even "it's not possible" is much appreciated.
Type Clearing Number Amount document_date
PY 2151885 -30 5/10/2010
INV 2151886 100 5/4/2010
INV 2151886 100 5/5/2010
PY 2151886 -50 5/6/2010
CM 2151886 -50 5/6/2010
PY 2151886 -100 5/10/2010
PY 2151887 -673.64 5/10/2010
PY 2151888 -7060 5/10/2010
The way the system works, within each CLEARING GROUP (as identified by the clearing numbers), each payment (PY) will be "applied" to the earliest open invoice, and close it out.
For example let's focus only on clearing #..886, first comes an invoice of 100, then comes another invoice of 100. The rules are that each time we have a Payment or Credit Memo, we apply (subtract) it to the EARLIEST OPEN invoice. Therefore, in this example, the first payment (PY) should close out 50 of the first invoice, leaving a remaining balance of 50. Then, the Credit Memo, (CM) should close the remainder of that first invoice. Finally, the last PY within the group should close the SECOND invoice.
The goal is to get the time between the credit memo, and the invoice it was applied to. I know this can be done in SQL via a loop function, but I am not so familiar with the language.
I have created many columns with IF statements, including a net running balance, but have not yet figured out how I would correctly calculate the time between each credit memo and early open invoice, within the clearing group.
I figure a vlookup may work, with conditions set that the invoice needs to be open. However, I would then need to run another column which would effectively close the next invoice per group. Keep in mind that there are many rows to the spreadsheet, and the groups may have as many as 10 credit memos in them.
Any help at all, even "it's not possible" is much appreciated.