Group by IDs and calculate

OCM

New Member
Joined
Sep 2, 2004
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Greetings,

Using Excel 365 and given the following in the attached sample:

Amount due = Settlement #1 – Collection amount (if Settlement #1 is not blank)
Amount due = Settlement #2 – Collection amount (if Settlement #1 is blank)
If Amount due = 0, then display “no amount due”

I would like to create a new column to calculate the itemized collection payments/amt. and display the amount due per CustID at the bottom. Please see the expected result in the attached sample.



TIA

Regards,
 

Attachments

  • Sample.png
    Sample.png
    243.7 KB · Views: 22
Hello, as I am not entirely sure what is the expected output, could you please share with us here whether it is what is depiced in the last column or whether is a list of unique IDs with the corresponding last (bold) amount?
 
Upvote 0
Thanks for the reply post.

The expected result is the last column which for this example I manually did the calculation and show the amount due at the bottom. Since my data consists of over 2000 records, I though a pivot table and/or applying formula to the logic will be a way to go.



TIA

Regards,
 
Upvote 0
Many thanks for the clarification. So, maybe something like:

Excel Formula:
=LET(
c,IF((B1=B2)=FALSE,(C2&D2)-E2,G1-E2),
IF(c=0,"no amount due",c))

Please note that the formula uses customer name instead of customer ID as it corresponds with your calculation as two different customer IDs (C004205 and C004206) are related to a single customer (#6).
 
Upvote 0
Same suggestion, just a little more compact.

25 03 03.xlsm
BCDEG
1NameS #1S #2AmtAmt Due
2Cust #17,000.00500.006,500.00
3Cust #17,000.00300.006,200.00
4Cust #17,000.00200.006,000.00
5Cust #2123.00123.00no amount due
6Cust #32,000.001,000.001,000.00
7Cust #32,000.00500.00500.00
8Cust #415,000.002,000.0013,000.00
9Cust #415,000.002,000.0011,000.00
10Cust #415,000.002,000.009,000.00
11Cust #572,800.001,605.0071,195.00
12Cust #572,800.0015,000.0056,195.00
13Cust #572,800.001,605.5454,589.46
14Cust #572,800.001,605.5452,983.92
15Cust #572,800.001,605.5451,378.38
16Cust #572,800.001,605.5449,772.84
17Cust #572,800.001,605.5448,167.30
18Cust #572,800.001,605.5446,561.76
19Cust #572,800.001,605.5444,956.22
20Cust #572,800.001,605.5443,350.68
21Cust #650,000.009,900.0040,100.00
22Cust #650,000.009,900.0030,200.00
23Cust #72,500.00500.002,000.00
24Cust #85,000.005,000.00no amount due
Amt Due
Cell Formulas
RangeFormula
G2:G24G2=LET(c,IF(B1=B2,G1,C2&D2)-E2,IF(c,c,"no amount due"))
 
Upvote 0
Or if you are just looking for the summary (final row for each customer)

25 03 03.xlsm
BCDEHIJ
1NameS #1S #2AmtNameAmt Due
2Cust #17,000.00500.00Cust #16,000.00
3Cust #17,000.00300.00Cust #2no amount due
4Cust #17,000.00200.00Cust #3500.00
5Cust #2123.00123.00Cust #49,000.00
6Cust #32,000.001,000.00Cust #543,350.68
7Cust #32,000.00500.00Cust #630,200.00
8Cust #415,000.002,000.00Cust #72,000.00
9Cust #415,000.002,000.00Cust #8no amount due
10Cust #415,000.002,000.00
11Cust #572,800.001,605.00
12Cust #572,800.0015,000.00
13Cust #572,800.001,605.54
14Cust #572,800.001,605.54
15Cust #572,800.001,605.54
16Cust #572,800.001,605.54
17Cust #572,800.001,605.54
18Cust #572,800.001,605.54
19Cust #572,800.001,605.54
20Cust #572,800.001,605.54
21Cust #650,000.009,900.00
22Cust #650,000.009,900.00
23Cust #72,500.00500.00
24Cust #85,000.005,000.00
Amt Due
Cell Formulas
RangeFormula
I2:J9I2=LET(b,B2:B24,u,UNIQUE(b),HSTACK(u,BYROW(u,LAMBDA(r,LET(c,TAKE(FILTER(C2:C24&D2:D24,b=r),1)-SUMIFS(E2:E24,b,r),IF(c,c,"no amount due"))))))
Dynamic array formulas.
 
Upvote 0
A gentle reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hagia_Sofia,

Thanks for the feedback. I’m glad you caught this. The formula should use customer IDs instead of customer name as the same customer can have multiple IDs at a different time. That is why I banded/grouped by the customer ID on my sample.

As a result, the amount due for both Customer #6s (C004205 & C004206 should be $40,000. I incorrectly put $30,056.54 for C004206 when I manually populated the amount due (column ‘g’). My apologies.



Peter_SSs, I applied both your suggestions and got the expected results in both. I even explored, altered your formula to =LET(c,IF(B1=B2,G1,C2&D2)-E2,IF(c,c,0)) if I decide to show $0.00 in the future.


We just need to alter the formula a bit and base it on the customer IDs instead of the customer’s name.

Also, I'll make sure to read and follow the posting rules.

TIA,

Regards,
 
Upvote 0
I even explored, altered your formula to =LET(c,IF(B1=B2,G1,C2&D2)-E2,IF(c,c,0)) if I decide to show $0.00 in the future.
If you were to use that copied-down formula & decided to show $0.00 then you would not need the IF() function or the LET() function at all as shown below in col G (also adjusted to use ID not name)
Also included to the right options to summarise with/without $0 & using ID not name

25 03 03.xlsm
ABCDEGHIJKLMNO
1IDNameS #1S #2AmtAmt DueIDNameAmt DueIDNameAmt Due
2aCust #17,000.00500.006,500.00aCust #16,000.00aCust #16,000.00
3aCust #17,000.00300.006,200.00bCust #2no amount duebCust #20.00
4aCust #17,000.00200.006,000.00cCust #3500.00cCust #3500.00
5bCust #2123.00123.000.00dCust #49,000.00dCust #49,000.00
6cCust #32,000.001,000.001,000.00eCust #543,350.68eCust #543,350.68
7cCust #32,000.00500.00500.00fCust #640,100.00fCust #640,100.00
8dCust #415,000.002,000.0013,000.00gCust #640,100.00gCust #640,100.00
9dCust #415,000.002,000.0011,000.00hCust #72,000.00hCust #72,000.00
10dCust #415,000.002,000.009,000.00iCust #8no amount dueiCust #80.00
11eCust #572,800.001,605.0071,195.00
12eCust #572,800.0015,000.0056,195.00
13eCust #572,800.001,605.5454,589.46
14eCust #572,800.001,605.5452,983.92
15eCust #572,800.001,605.5451,378.38
16eCust #572,800.001,605.5449,772.84
17eCust #572,800.001,605.5448,167.30
18eCust #572,800.001,605.5446,561.76
19eCust #572,800.001,605.5444,956.22
20eCust #572,800.001,605.5443,350.68
21fCust #650,000.009,900.0040,100.00
22gCust #650,000.009,900.0040,100.00
23hCust #72,500.00500.002,000.00
24iCust #85,000.005,000.000.00
25
Amt Due (3)
Cell Formulas
RangeFormula
I2:K10I2=LET(a,A2:A24,u,UNIQUE(a),HSTACK(u,XLOOKUP(u,a,B2:B24),BYROW(u,LAMBDA(r,LET(c,TAKE(FILTER(C2:C24&D2:D24,a=r),1)-SUMIFS(E2:E24,a,r),IF(c,c,"no amount due"))))))
M2:O10M2=LET(a,A2:A24,u,UNIQUE(a),HSTACK(u,XLOOKUP(u,a,B2:B24),BYROW(u,LAMBDA(r,TAKE(FILTER(C2:C24&D2:D24,a=r),1)-SUMIFS(E2:E24,a,r)))))
G2:G24G2=IF(A1=A2,G1,C2&D2)-E2
Dynamic array formulas.
 
Upvote 0
Solution
Peter_SSs,

Thank you so much for enhancing the formulas to achieve the expected results. I wasn’t familiar with UNIQUE, HSTACK, LAMBDA etc. I’ll search online to make myself familiar with their usage.

Many thanks!

Regards,
 
Upvote 0

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