I'm trying to build a Secret Santa app for my company, but I'm trying to contain all functionality within the Power App - no SP lists and no workflows.
I have a solution built that appears to be 99% reliable, but there's one scenario I haven't been able to crack.
This is the rough approach:
- User selects multiple people from a combo box, and this creates 2 identical collections containing the email address and name of each selected employee.
I then shuffle both collections:
ClearCollect(
col_Team,
Shuffle(col_Team)
);
ClearCollect(
col_Team2,
Shuffle(col_Team2)
);
Next, I create a new collection to contain the pairs of Gifters and Receivers, and the aim is to:
The code below generates a perfect match up MOST of the time:
ForAll(
col_Team As _gifters,
Collect(
col_Matches,
{
Gifter: _gifters.Email,
Receiver: First(
Shuffle(
Filter(
col_Team2 As _receivers,
_receivers.Email <> _gifters.Email && !(_receivers.Email in col_Matches.Receiver)
)
)
).Email
}
);
);
Most of the time, my new collection will look something like this:
Gifters: | Recievers: |
Person A | Person C |
Person B | Person E |
Person C | Person A |
Person D | Person B |
Person E | Person D |
However, sometimes I can get something like this:
Gifters: | Recievers: |
Person A | Person C |
Person B | Person D |
Person C | Person A |
Person D | Person B |
Person E |
It seems that the formula can't account for the possibility that the last Gifter from the first collection hasn't already been drawn as a Receiver from the second collection, and therefore they can't be assigned as themselves and will simply be skipped.
I've tried various approaches, but have run into all sorts of difficulties using Lookups within ForAll loops etc.
The code above seems to be the most effeicient and most reliable, but it's not 100%.
Does anyone know how I can achieve 100% reliability without going beyond the app and using lists or workflows?
Thanks.
User | Count |
---|---|
258 | |
111 | |
95 | |
48 | |
41 |