Hoping some formula-whiz might be able to lend a hand here. I am trying to write a formula that will accomplish the following:
Given a set of X values, each of which belongs to one of Y classes, I want to generate all possible combinations of values, consisting of a single value for each class, without repeating any combination.
I know this is fairly straightforward math, but math isn’t my strong suit Any help would be appreciated.
But since we’re going to deal with the arbitrary number of Ys, we need to find a different way. And that would be counting in circles with integer division and modulo operations, in a similar way like I once did here:
I can take a go at this problem in some 30 minutes
Thanks guys @Paul_Danyliuk and @Connor_McCormick1! I guess a more straightforward way to have explained the problem is that I am trying to find the most efficient way of calculating the cartesian product of multiple data sets. I’ve tried a bundle of not very elegant solutions and just can’t seem to crack it. Really value any insight you could offer.
Woah. This is incredible. Thank you, @Paul_Danyliuk! Pushing my luck here, but I had one more question: Is there an easy modification I could make if I wanted to enforce limits on certain items? I.e. continuing with your grocery aisle example, let’s say I only wanted to allow three combinations to include an apple.
In this case, it wouldn’t be important to the end result. That said, I suppose the challenge is how to enforce this in the formula. I’m combing through the algo you wrote right now trying to work this out, but it’s taking me a minute to catch up to your logic. I’m not as bright as you
Well, it would benefit to know the actual use case
The easiest way is probably to add the conditional logic in the end. Just start skipping items if CV meets certain condition (e.g. let 1, 2, 3 through and then skip over the next 9 items, then let three items through again and so on)
BTW the formula gets much easier if you have your Group 1, 2, 3 as lookups from another table. That way you can calculate things like items per group, counts, and the cumulative product as columns on that Groups table, and the end formula will basically be only this last piece (no Nth(2/3/4)s on nested lists).