LAST 3 Events in 2 Seperate Columns?

AYouQueTai

New Member
Joined
Sep 14, 2019
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have the NHL hockey games listed in my Schedule sheet like so.

Game ID | Status | Date | Visitor | Home | Vis Goals | Home Goals |
02001 | Completed | Jan18 | Montreal | Vancouver | 3 | 5
02002 | Completed | Jan18 | Toronto | Winnipeg | 4 | 2
02003 | Completed | Jan19 | Ottawa | Montreal | 5 | 1
02004 | Completed | Jan19 | Ottawa | Toronto | 6 | 2
02005 | Completed | Jan 20 | Montreal | Toronto | 3 | 2
02006 | Scheduled | Jan21 | Vancouver| Montreal | |

I would like to make a team sheet that lists a team's Last 3 "Completed" game Results.
Whether they were Visitor or Home doesn't matter
So in the Montreal Team Sheet it would display

Visitor | Home | Vis Goals | Home Goals |
Montreal | Vancouver | 3 | 5
Ottawa | Montreal | 5 | 1
Montreal | Toronto | 3 | 2

I can't figure this one out, can any of you?
Thanks,
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Something like this perhaps?
spill fails.xlsx
ABCDEFG
1Game ID Status Date Visitor Home Vis Goals Home Goals
22001CompletedJan-18MontrealVancouver35
32002CompletedJan-18TorontoWinnipeg42
42003CompletedJan-19OttawaMontreal51
52004CompletedJan-19OttawaToronto62
62005CompletedJan-20MontrealToronto32
72006ScheduledJan-21VancouverMontreal
8
9Montreal
10Visitor Home Vis Goals Home Goals
11MontrealVancouver35
12OttawaMontreal51
13MontrealToronto32
Sheet4
Cell Formulas
RangeFormula
A11:D13A11=INDEX(FILTER(D2:G7,((D2:D7=A9)+(E2:E7=A9))*(F2:F7<>"")*(G2:G7<>"")),SEQUENCE(3,,COUNTIFS(D2:E7,A9,F2:G7,"<>")-2),{1,2,3,4})
Dynamic array formulas.
 
Upvote 0
How about this!

Excel Message board.xlsm
ABCDEFG
1Game ID Status Date Visitor Home Vis Goals Home Goals
22001Completed Jan18 MontrealVancouver35
32002Completed Jan18 TorontoWinnipeg42
42003Completed Jan19 OttawaMontreal51
52004Completed Jan19 OttawaToronto62
62005Completed Jan 20 MontrealToronto32
72006 Scheduled Jan21 VancouverMontreal11
8
9MontrealCompleted(last 3 match)
10No. Visitor Home Vis Goals Home Goals
111MontrealVancouver35
122OttawaMontreal51
133MontrealToronto32
14
15
Sheet3
Cell Formulas
RangeFormula
B11:E13B11=INDEX(D$2:D$7,AGGREGATE(15,6,(((ROW($D$2:$D$7)-ROW($D$2)+1)))/(($B$2:$B$7="Completed")*((--($A$9=$D$2:$D$7))+(--($A$9=$E$2:$E$7)))>0),$A11))
 
Upvote 0
Slight tweak to Jason's idea to cater for less than 3 games completed
+Fluff v2.xlsm
ABCDEFG
1Game ID Status Date Visitor Home Vis Goals Home Goals
22001Completed01/01/2018MontrealVancouver35
32002Completed01/01/2018TorontoWinnipeg42
42003Completed01/01/2019OttawaMontreal51
52004Completed01/01/2019OttawaToronto62
62005Completed01/01/2020MontrealToronto
72006Scheduled01/01/2021VancouverMontreal
8
9Montreal2
10Visitor Home Vis Goals Home Goals
11MontrealVancouver35
12OttawaMontreal51
13
Master
Cell Formulas
RangeFormula
B9B9=MIN(3,COUNTIFS(D2:E7,A9,F2:G7,"<>"))
A11:D12A11=INDEX(FILTER(D2:G7,((D2:D7=A9)+(E2:E7=A9))*(F2:F7<>"")*(G2:G7<>"")),SEQUENCE(B9,,COUNTIFS(D2:E7,A9,F2:G7,"<>")-B9+1),{1,2,3,4})
Dynamic array formulas.
 
Upvote 0
Nice one @Fluff, that was something I hadn't thought of :eek:

Not done full evaluation but I think that @alz suggestion would be the most efficient and practical. Given that it's a fixed set of results, I don't see any advantage to using dynamic arrays for this, just appear to be using them out of habit now.

A couple of tweaks to @alz formula, nothing wrong with the original but surplus parenthesis are kind of an ocd thing for me
Excel Formula:
=INDEX(D$2:D$7,AGGREGATE(15,6,ROW($D$2:$D$7)/(($B$2:$B$7="Completed")*(($A$9=$D$2:$D$7)+($A$9=$E$2:$E$7))>0),$A11)-ROW($D$2)+1)
I moved the row adjustment as well, wonder if anyone (except @Fluff) can see why.
 
  • Like
Reactions: alz
Upvote 0
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Another option with dynamic arrays
+Fluff v2.xlsm
ABCDEFG
1Game ID Status Date Visitor Home Vis Goals Home Goals
22001Completed01/01/2018MontrealVancouver35
32002Completed01/01/2018TorontoWinnipeg42
42003Completed01/01/2019OttawaMontreal51
52004Completed01/01/2019OttawaToronto62
62005Completed01/01/2020MontrealToronto15
72006Scheduled01/01/2021VancouverMontreal
8
9Montreal3
10Visitor Home Vis Goals Home Goals
11MontrealVancouver35
12OttawaMontreal51
13MontrealToronto15
14
15MontrealVancouver35
16OttawaMontreal51
17MontrealToronto15
Master
Cell Formulas
RangeFormula
B9B9=MIN(3,COUNTIFS(D2:E7,A9,F2:G7,"<>"))
A11:D13A11=INDEX(FILTER(D2:G7,((D2:D7=A9)+(E2:E7=A9))*(F2:F7<>"")*(G2:G7<>"")),SEQUENCE(B9,,COUNTIFS(D2:E7,A9,F2:G7,"<>")-B9+1),{1,2,3,4})
A15:D17A15=IFERROR(INDEX(D$2:D$7,AGGREGATE(14,6,(ROW($D$2:$D$7)-ROW($D$2)+1)/(($D$2:$D$7=$A$9)+($E$2:$E$7=$A$9))/($B$2:$D$7="Completed"),ROWS($A15:$A$17))),"")
Dynamic array formulas.


@alz
Your formula will pull the 1st matches, not the last 3 ;)
 
  • Like
Reactions: alz
Upvote 0
@Fluff you are right ! my mistake.
here is the corrected formula with a slight tweak. I like Double negative -- because easy to evaluate the formula.

Excel Message board.xlsm
ABCDEFG
1Game ID Status Date Visitor Home Vis Goals Home Goals
22001Completed Jan18 MontrealVancouver35
32002Completed Jan18 torantoWinnipeg42
42003Completed Jan19 OttawaMontreal51
52004Completed Jan19 OttawaToronto62
62005Completed Jan 20 MontrealToronto32
72006 Scheduled Jan21 VancouverMontreal
8
9MontrealCompleted(last 3 match)
10 Visitor Home Vis Goals Home Goals
11MontrealVancouver35
12OttawaMontreal51
13MontrealToronto32
Sheet3
Cell Formulas
RangeFormula
A11:D13A11=INDEX(D$2:D$7,AGGREGATE(14,6,(ROW($D$2:$D$7)-ROW($D$2)+1)/((--($B$2:$B$7=$B$9))+(--($A$9=$D$2:$D$7))+(--($A$9=$E$2:$E$7))=2),ROWS($A11:$A$13)))
 
Upvote 0
Solution
I like Double negative -- because easy to evaluate the formula.
They also add extra calculation steps to the formula, reducing the efficiency. Not much difference on a small array like this, but if you had a few thousand rows of data.
 
Upvote 0
Jason, Sorry that I didn't have my account details up to date, the FILTER command isn't available in Excel 2013 so I wasn't able to test your solution. I guess it's time to upgrade.
ALZ, thank you very much. It works great and will save me lots of time!
 
  • Like
Reactions: alz
Upvote 0
@AYouQueTai Thanks for your feedback.


@jasonb75 thanks for your advice !

For my learning,.
I created data for 100000 Rows and . download timer VBA code from Microsoft
Selected answer cells (total 12 for each) and tested the calculation speed
A little tweak formula of fluff is the fasted and follow by yours. ( not included for 365 version)

Excel Message board - Copy.xlsm
MNOPQ
3Rank
43ALZ=INDEX(D$2:D$100000,AGGREGATE(14,6,(ROW($D$2:$D$100000)-ROW($D$2)+1)/((--($B$2:$B$100000=$J$4))+(--($I$4=$D$2:$D$100000))+(--($I$4=$E$2:$E$100000))=2),ROWS($I6:$I$8)))
5average
60.5376166670.546340.534220.53229
7
84Fluff original=IFERROR(INDEX(D$2:D$100000,AGGREGATE(14,6,(ROW($D$2:$D$100000)-ROW($D$2)+1)/(($D$2:$D$100000=$I$10)+($E$2:$E$100000=$I$10))/($B$2:$D$100000="Completed"),ROWS($I11:$I$13))),"")
9average
100.7380066670.743780.733620.73662
11
122Jason=INDEX(D$2:D$100000,AGGREGATE(14,6,ROW($D$2:$D$100000)/(($B$2:$B$100000="Completed")*(($I$15=$D$2:$D$100000)+($I$15=$E$2:$E$100000))>0),$H16)-ROW($D$2)+1)
13average
140.434310.435470.434920.43254
15
161Fluff ( a little tweak)=IFERROR(INDEX(D$2:D$100000,AGGREGATE(14,6,(ROW($D$2:$D$100000)-ROW($D$2)+1)/(($D$2:$D$100000=$I$20)+($E$2:$E$100000=$I$20))/($B$2:$B$100000="Completed"),ROWS($I21:$I$23))),"")
17average
180.4287033330.430540.426730.42884
30
Cell Formulas
RangeFormula
M4,M16,M12,M8M4=RANK(N6,$N$6:$N$18,1)
N6,N18,N14,N10N6=AVERAGE(O6:Q6)
 
Upvote 0

Forum statistics

Threads
1,216,129
Messages
6,129,055
Members
449,484
Latest member
khairianr

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