Countifs? Count events in a range if something doesn't happen in another range

AYouQueTai

Board Regular
Joined
Sep 14, 2019
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hello,

In hockey, teams usually play 5-6 consecutive games at home and then 5-6 games on the road.
I am trying to accomplish two things,
1 - Count the number of consecutive games the visiting team will play as visitors before returning home.
2 - Figure out which game, in the range of consecutive games, they are currently playing. IE Game 2 of 6

So using Nashville as an example
Cell F2 - Formula 1- count the number of consecutive games Nashville (Column H) plays as Visitor before returning home. In this case they are listed in H2 and H22 then at home at K45. The moment they play a game at home (Column K) the visitor count ends at 2.
Formula 2- Identify which game in the road trip they are currently on. IE. F2 would be 1 of 2. F22 would be 2 of 2.

I've tried coming up with a solution using countifs and Sumproduct but can't figure it out.
Any suggestions?

NHL 2023-2024.xlsx
ABCDEFGHIJKLM
1GameIDStatusDayDateTime (AST)VGCVDBGVisitorHGCHDBGHomeArenaEV
2020001CompletedTuesdayOct-1018:3050Nashville50Tampa Bay
3020002CompletedTuesdayOct-1021:0050Chicago50Pittsburgh
4020003CompletedTuesdayOct-1023:4550Seattle50Vegas
5020004CompletedWednesdayOct-1120:0050Ottawa50Carolina
6020005CompletedWednesdayOct-1120:0050Montreal50Toronto
7020006CompletedWednesdayOct-1120:300Chicago50Boston
8020007CompletedWednesdayOct-1123:0050Winnipeg50Calgary
9020008CompletedWednesdayOct-1123:1550Colorado50Los Angeles
10020009CompletedWednesdayOct-1123:1550Edmonton50Vancouver
11020010CompletedThursdayOct-1220:0050NY Rangers50Buffalo
12020011CompletedThursdayOct-1220:0050Philadelphia50Columbus
13020012CompletedThursdayOct-1220:3050Detroit50New Jersey
14020013CompletedThursdayOct-1221:0050St-Louis50Dallas
15020014CompletedThursdayOct-1221:0050Florida50Minnesota
16020015CompletedThursdayOct-1221:001Seattle1Nashville
17020016CompletedThursdayOct-1223:301Vegas50San Jose
18020017CompletedFridayOct-1320:0050Arizona0New Jersey
19020018CompletedFridayOct-1320:302Pittsburgh50Washington
20020019CompletedSaturdayOct-1414:151Philadelphia2Ottawa
21020020CompletedSaturdayOct-1417:151Florida2Winnipeg
22020021CompletedSaturdayOct-1420:001Nashville2Boston
23020022CompletedSaturdayOct-1420:001NY Rangers1Columbus
24020023CompletedSaturdayOct-1420:003Tampa Bay1Detroit
25020024CompletedSaturdayOct-1420:002Chicago2Montreal
26020025CompletedSaturdayOct-1420:002Calgary0Pittsburgh
27020026CompletedSaturdayOct-1420:001Minnesota2Toronto
28020027CompletedSaturdayOct-1420:301Buffalo50NY Islanders
29020028CompletedSaturdayOct-1421:001Seattle1St-Louis
30020029CompletedSaturdayOct-1423:002Vancouver2Edmonton
31020030CompletedSaturdayOct-1423:002Colorado1San Jose
32020031CompletedSaturdayOct-1423:0050Anaheim1Vegas
33020032CompletedSaturdayOct-1423:302Carolina2Los Angeles
34020033CompletedSundayOct-1520:000Tampa Bay0Ottawa
35020034CompletedSundayOct-1521:300Carolina0Anaheim
36020035CompletedMondayOct-1620:001Detroit1Columbus
37020036CompletedMondayOct-1620:001Florida2New Jersey
38020037CompletedMondayOct-1620:002Arizona1NY Rangers
39020038CompletedMondayOct-1620:001Chicago1Toronto
40020039CompletedMondayOct-1620:001Calgary2Washington
41020042CompletedTuesdayOct-1719:002Vancouver2Philadelphia
42020041CompletedTuesdayOct-1720:002Minnesota2Montreal
43020040CompletedTuesdayOct-1720:301Tampa Bay2Buffalo
44020043CompletedTuesdayOct-1720:300Arizona2NY Islanders
45020044CompletedTuesdayOct-1721:002Edmonton2Nashville
46020045CompletedTuesdayOct-1721:002Los Angeles2Winnipeg
47020046CompletedTuesdayOct-1723:002Colorado2Seattle
48020047CompletedTuesdayOct-1723:301Carolina2San Jose
49020048CompletedTuesdayOct-1723:304Dallas2Vegas
50020049CompletedWednesdayOct-1820:001Washington2Ottawa
51020050CompletedWednesdayOct-1820:303Pittsburgh1Detroit
Schedule
Cell Formulas
RangeFormula
C2:C51C2=TEXT([@Date],"dddd")
G2:G51G2=IFERROR(DAYS([@Date]-1,IFERROR(@INDEX([Date],AGGREGATE(14,6,(ROW([Visitor])-ROW(Schedule!$E$2)+1)/([Date]<$D2)/(($H2=[Visitor])+($H2=[Home])),ROWS($G2:$G2))),"")),50)
J2:J51J2=IFERROR(DAYS([@Date]-1,IFERROR(@INDEX([Date],AGGREGATE(14,6,(ROW([Visitor])-ROW(Schedule!$E$2)+1)/([Date]<$D2)/(($K2=[Visitor])+($K2=[Home])),ROWS($J2:$J2))),"")),50)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M2:M884Expression=$M2=""textNO
M2:M884Expression=$M2="Y"textNO
Cells with Data Validation
CellAllowCriteria
B2:B51List=INDIRECT("StatusDrop[Status]")
K2:K51List=INDIRECT("Teams[Teams]")
H2:H51List=INDIRECT("Teams[Teams]")


Thanks,
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this in F2 and see if it gives the correct results for part 1 of your question. It gives a different result for your example but I note that you appear to have overlooked Nashville's home game in K16.

Excel Formula:
=INDEX(FREQUENCY(IF([Visitor]=[@Visitor],ROW([Visitor])),IF(COUNTIF([Home],[@Visitor]),IF([Home]=[@Visitor],ROW([Visitor])),MAX(ROW([Home])))),COUNTIF([[#Headers],[Home]]:[@Home],[@Visitor])+1)
 
Upvote 1
Solution
You're right I did overlook K16, sorry about that. But thank you very much it works great for that part of the problem
 
Upvote 0

Forum statistics

Threads
1,224,912
Messages
6,181,699
Members
453,063
Latest member
DoingWorkThings

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