Excel dynamic array challenge: sequentially filtering rows by chaining winners to their next match
Excel version: 365
For quite some time now I've been working on a silly project on my spare time. It's not something serious, and my issue is not even critical to what I'm trying to do. It is basically a compilation of (almost) all international football (soccer) matches.
You can download the full workbook here to play around with it.
Now here's my situation:
Consider that I have a range comprised of 6 columns and several rows, named AllTimeMatches
Column 1 is the date of a football match.
Column 2 is the home team.
Column 3 is the home team score.
Column 4 is just a separator.
Column 5 is the away team score.
Column 6 is the away team.
I've already used LET(r,AllTimeLeagueMatches,FILTER(r,INDEX(r,,3)<>INDEX(r,,5))) to do away with matches that ended in a draw, because for this part of the project I'm only looking at matches with a win/loss result.
What I want now is to look on a row by row basis for the next match by the winner of the previous match.
Example: I'm intentionally omitting the column 1 values because they are irrelevant for what I need. Let's assume the range has these rows:
- Northern Ireland 7 x 2 Wales
- England 6 x 1 Northern Ireland
- Wales 3 x 4 Scotland
- Scotland 2 x 1 Northern Ireland
- England 2 x 1 Scotland
- Canada 1 x 4 United States
- Canada 1 x 2 United States
- Canada 1 x 2 United States
- Scotland 5 x 1 Canada
- Northern Ireland 0 x 2 England
In this example, because Northern Ireland won the first match, you need to look for the next match played by Northern Ireland.
So, Northern Ireland plays against England in row 2 and loses. Because England won this one, you'll look for the next match played by England.
England's next match is in row 5, so rows 3 and 4 will not be shown.
England wins again in row 5, so you continue looking for England.
Every time the winner changes, you will look for the next match played by the winner until the last row of the range, or until there are no more matches played by the current winner, whichever comes first.
In this example, the result would be:
Northern Ireland 7 x 2 Wales
England 6 x 1 Northern Ireland
England 2 x 1 Scotland
Northern Ireland 0 x 2 England
Is it doable? I've already asked AI. It says it is doable, but none of their proposed formulas work, and I can't figure it out with my current knowledge.
Again, no need to burn your neurons with this, but if something figures this out, I'd love it.
If my query is not clear, just ask, I'll be more than happy to clarify.
[link] [comments]
Want to read more?
Check out the full article on the original site