Permutation & Combination Problem in Excel for Creating Payment Groups

wouldbeca

Board Regular
Joined
Aug 31, 2014
Messages
51
Input Data:

I have a data table with 3 columns:

  • Supplier No.
  • Location No.
  • Payable/(Receivable Amount


Example of a sample part of Input data is attached

Output Data required:


In order to process payment to several suppliers every day, I need to create “payment groups” comprising of Supplier Nos and Location Nos in our accounting software.

Conditions

Please help me with excel formula/VBA code, to determine the best possible combination sets of Supplier No. and Location ID for creating “payment groups” with the below conditions:

  • No. of payment groups prepared is minimum.
  • Maximum 10 No. of location IDs can be used in each group.
  • Net grouped amount of each and every vendor in any payment group is positive.
In case of any further query, please revert.

Book4
ABC
1Supplier No.Location No.Amount Payable/-Receivable
2270291107,36,654
311115,78,320
4270941126,62,450
52709011332,11,385
6270691142,72,908
72702611414,27,552
8270711152,62,161
927094116-512
101172,66,339
11118-12,278
12119-3,070
1312015,56,969
142703411772,552
151201,63,404
16270591201,09,069
1712118,431
181221,26,463
192704112318,22,797
20270951232,14,332
211241,14,217
22270121253,95,874
23270621122,54,339
24270101159,40,853
25270931261,78,133
262704312798,669
271231,17,560
282705212797,295
2912359,452
302705712733,101
311231,17,027
32270161271,64,141
33270041271,29,272
341231,17,494
352708112732,842
361232,35,920
372709512798,447
381231,17,627
39270031271,29,468
401231,17,560
412701212733,816
421231,17,828
43270231271,31,882
44270981271,32,013
45270661271,05,635
46270671271,64,940
472708812733,816
481231,17,227
49270551231,18,094
50128-2,444
5127071129-1,000
5213054,177
53270471314,854
541322,81,784
55270531336,549
5613211,54,029
5713418,755
58270541321,22,018
59270551338,826
601324,17,359
612706611210,08,036
62270871125,49,803
63270121128,70,079
642707912733,160
651231,17,828
66128-977
672707813572,300
6827037136-2,08,524
691375,11,147
7011277,901
7127038136-1,37,044
72137-20,005
7311228,934
74270531373,15,715
75270761111,32,996
76270771112,46,981
77270851137,51,573
78270971382,25,628
79270071385,29,166
80270081384,72,631
81270501391,73,094
82270511395,47,820
83270011157,12,246
84270101153,66,801
85270401154,74,174
Sheet1
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Everyone thinks the only solution to any problem is VBA. Learn Power Query! Playlists here and here. Thank you for using XL2BB though!
Preamble - changing data's orientation (L/R/C) should only be done when needed. If left alone, numbers will always justify right, and text will always justify left. It's a powerful tool to tell what's going on with your data, and never format money without two digits if it's just data. Your 3rd column is actually Decimal Numbers. That said, all 3 columns of your sample are numbers, and the original data has 84 columns, and there are only 82 unique combinations of the first and second column! Got that with Power Query in about a minute - an identical table with 82 rows, and the rows where both Column 1 and 2 were the same added together.
I was able to take the results of that table and subtotal column 3 resulting in two columns - one for each supplier with the totals for each supplier in the 2nd column - 45 suppliers.

If you pull that data in from a file, you could create a master to pull in the data, transform it as needed, have completed, updated tables in a couple (not even a few) minutes. Here's what I got:

Excel VBA User Defined Function To Generate A Dynamic Array - 2516.xlsm
EFGHIJ
1Supplier No.Location No.AP/R TotalsSupplier No.AP/R by Supplier
227029110736,653.85270292,314,973.84
3270291111,578,319.99270942,469,899.26
427094112662,450.29270903,211,384.73
5270901133,211,384.7327069272,907.81
627069114272,907.81270261,427,552.26
7270261141,427,552.2627071315,337.49
827071115262,160.8327034235,955.85
927094116-511.6027059253,962.21
1027094117266,339.36270411,822,797.21
1127094118-12,278.4027095544,622.15
1227094119-3,069.60270121,417,597.09
13270941201,556,969.2127062254,339.03
142703411772,551.56270101,307,653.85
1527034120163,404.2927093178,132.88
1627059120109,068.6027043216,229.36
172705912118,430.9627052156,747.29
1827059122126,462.6527057150,128.20
19270411231,822,797.2127016164,141.47
2027095123331,958.3827004246,766.67
2127095124114,217.2527081268,762.02
2227012125395,873.6327003247,027.94
2327062112254,339.0327023131,882.17
24270101151,307,653.8527098132,012.84
2527093126178,132.88270661,113,670.41
262704312798,669.3827067164,939.67
2727043123117,559.9827088151,043.83
282705212797,295.1127055541,836.22
292705212359,452.1827047286,638.44
302705712733,101.36270531,495,047.86
3127057123117,026.8427054122,018.12
3227016127164,141.4727087549,803.29
3327004127129,272.2127079150,010.87
3427004123117,494.462707872,299.95
352708112732,841.8427037380,524.36
3627081123235,920.1827038-128,115.25
372709512798,446.5227076132,996.21
3827003127129,467.9627077246,980.73
3927003123117,559.9827085751,572.54
402701212733,816.4327097225,628.32
4127012123117,828.0627007529,166.28
4227023127131,882.1727008472,630.89
4327098127132,012.8427050173,094.48
4427066127105,634.5027051547,819.99
4527067127164,939.6727001712,246.26
462708812733,816.4327040474,174.38
4727088123117,227.40
4827055123118,094.12
4927055128-2,443.50
5027071129-1,000.00
512707113054,176.66
52270471314,854.02
5327047132281,784.42
54270531336,549.15
55270531321,154,028.89
562705313418,754.96
5727054132122,018.12
58270551338,826.17
5927055132417,359.43
60270661121,008,035.91
6127087112549,803.29
6227012112870,078.97
632707912733,160.21
6427079123117,828.06
6527079128-977.40
662707813572,299.95
6727037136-208,523.75
6827037137511,147.10
692703711277,901.01
7027038136-137,044.12
7127038137-20,004.71
722703811228,933.58
7327053137315,714.86
7427076111132,996.21
7527077111246,980.73
7627085113751,572.54
7727097138225,628.32
7827007138529,166.28
7927008138472,630.89
8027050139173,094.48
8127051139547,819.99
8227001115712,246.26
8327040115474,174.38
Sheet3


Power Query M Code for the first table:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="tblPmts"]}[Content],
    FilledDown = Table.FillDown(Source,{"Supplier No."}),
    ChangedType = Table.TransformColumnTypes(FilledDown,{{"Supplier No.", Int64.Type}, {"Location No.", Int64.Type}, {"Amount Payable/-Receivable", type number}}),
    GroupedRows = Table.Group(ChangedType, {"Supplier No.", "Location No."}, {{"AP/R Totals", each List.Sum([#"Amount Payable/-Receivable"]), type nullable number}})
in
    GroupedRows
For the second table (which uses the results of the first query/table):
Power Query:
let
    Source = tblPmts,
    GroupedRows = Table.Group(Source, {"Supplier No."}, {{"AP/R by Supplier", each List.Sum([#"AP/R Totals"]), type nullable number}})
in
    GroupedRows

EZPZ!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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