-3

I have a spreadsheet that has 6 records in it. Each record has an amount field. I need to write a process to give me a total amount for every possible combination of rows. For Example

Total = row1 amount
Total = row2 amount
Total = row3 amount
Total = row4 amount
Total = row5 amount
Total = row6 amount
Total = row1 amount + row2 amount
Total = row1 amount + row3 amount
Total = row1 amount + row4 amount
Total = row1 amount + row5 amount
Total = row1 amount + row6 amount
Total = row1 amount + row2 amount + row3 amount
Total = row1 amount + row2 amount + row4 amount

etc.

Does anyone have an algorithm or code example that will do this?

Community
  • 1
  • 1
Cass
  • 537
  • 1
  • 7
  • 24
  • Just to be sure, you want 6! different results? At least I think that is the math... – PartyHatPanda Oct 24 '16 at 19:22
  • 1
    Also, what have you tried? Do you have any code done yourself? Check out [How To Ask](http://stackoverflow.com/help/how-to-ask) to help us help you! – PartyHatPanda Oct 24 '16 at 19:24
  • #PartyHatPanda -- No I believe it would be like 63, total possible combinations for 6 records. I want every possible combination that, in this case, 6 records can generate. I haven't tried anything yet because I just can't get it straight in my head how it should work. – Cass Oct 24 '16 at 19:30
  • Yes you are right, I only got 63 values running it. Try using nested for loops and an array to hold the individual sums. – PartyHatPanda Oct 24 '16 at 19:44
  • #PartyHatPanda -- I want my code to be dynamic enough to run for any number of records. This example has 6 records, another account may only have 2 records, another may have 15 records. I need to figure out dynamically how to created the loops. – Cass Oct 24 '16 at 20:24

1 Answers1

0

Background:
You need to know about permutation and combination in order to define what are you exactly going for. By the context given I assume you need combination.
Solution approach:
Given the main topic approach, there are plenty of topics that give an approach to that, here and here are examples in stackoverflow database. I do not find useful just to copy paste the code form their answers nor write it explicitly for you just to copy paste.
Further advices:
There are plenty of templates designed for this matter, this is a good one to modify to your needs, however the interface is in spanish

Community
  • 1
  • 1
Sgdva
  • 2,800
  • 3
  • 17
  • 28