Subtract first non-zero value in range defined by OFFSET/COUNTIF; Suggestions or ideas?

Kronofile

New Member
Joined
Mar 5, 2015
Messages
1
First time poster, please let me know (gently) if I'm in the wrong place or otherwise doing something incorrectly.

I'm currently out of ideas on how to achieve something that might be easier to show than describe:

Customer_NumberOriginal_chargeFirst_TransactionRevised_chargeAdditional/ReturnShould_be
00001950000000$480.00TRUE$507.00$27.00$27.00
00001950000000$480.00FALSE$0.00$0.00$0.00
00001950000000$480.00FALSE$0.00$0.00$0.00
00001950000000$480.00FALSE$507.00Do it$0.00
00001950000000$480.00FALSE$507.00Do it$0.00
00001950000000$480.00FALSE$0.00$0.00$0.00
00001950000000$384.00FALSE$407.00Do it-$100.00
00001950000000$383.00FALSE$405.00Do it-$2.00
00001950000000$383.00FALSE$405.00Do it$0.00
00001950000000$383.00FALSE$405.00Do it$0.00
00001950000000$383.00FALSE$0.00$0.00$0.00
00001950000000$383.00FALSE$405.00Do it$0.00
00001950000000$383.00FALSE$0.00$0.00$0.00
00001950000000$383.00FALSE$0.00$0.00$0.00
00001950000000$383.00FALSE$405.00Do it$0.00
00001950000000$383.00FALSE$398.00Do it-$7.00
00001950000000$383.00FALSE$0.00$0.00$0.00
00001950000000$380.00FALSE$398.00Do it$0.00
00016020000000$88.00TRUE$63.00-$25.00-$25.00
00016020000000$88.00FALSE$0.00$0.00$0.00
00016020000000$88.00FALSE$0.00$0.00$0.00
00016020000000$88.00FALSE$0.00$0.00$0.00
00016020000000$88.00FALSE$0.00$0.00$0.00
00016020000000$88.00FALSE$62.00Do it-$1.00
00016020000000$88.00FALSE$62.00Do it$0.00
00016020000000$138.00FALSE$97.00Do it$34.00

<tbody>
</tbody>

I've got a list of transactions, in processed date order, for customers identified by unique values in Column A above. Column B shows a "running total" of what we originally charged, while Column D shows a revised charge per transaction. This is why Column B always has a number, while Column D will contain zeros (no change in running total means no change during that transaction). I used column C to identify the first transaction for a particular customer number, while column E contains my formula:

<code>=IF(D2=0,0,IF(C2=TRUE,D2-B2,IF(SUM(OFFSET(D2,(COUNTIF($A$1:A2,A2)-1)*-1,0,COUNTIF($A$1:A2,A2)-1))=0,D2-B2,"Do it")))</code>

I've gotten as far as the "Do it" bit (because I don't know how to make it do it!). Column F shows what I'm trying to return for the "Do it" values in Column E.

My main problem is comparing a "running total" to a per-transaction amount. Also the first transaction for a customer could be a zero value, so I've tried my best to deal with that in the above formula.

I'm not sure my approach is appropriate, but I've used a combination of COUNTIF and OFFSET to dynamically define a range for the formula, a range consisting of the all records for a particular Customer Number which precede the current record. If the sum of preceding records is zero, and the current record is non-zero, i know it's my first non-zero record and proceed with Column D - Column B.

When I come to a record for a customer that is a non-zero value in Column D, and it is preceded by at least one non-zero value for that same customers records above it, I want to subtract the first non-zero value counting up from the current record.

I've seen some examples of array formulas that will subtract the first non-zero value it finds in a column, but I don't have a lot of experience with SCE formulas and wasn't sure how to adapt them to my purposes.

Any help is appreciated! Even just a suggestion on a combination of formulas or a different approach to my table might put me on the right track.

Thanks all.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top