Based on how to find the MAX time value after midnight in a range I attempted to count the distinct number of items in the range. I was unsuccessful. Attached is the example spreadsheet. The issues is with the Route Breakdown by Day tab in columns F and G.

For column F the simple =COUNTIFS('Table 1'!$A$2:$A$353,A2,'Table 1'!$C$2:$C$353,'Route Breakdown by Day'!B2) formula does not account for items past midnight (as they fall on a different day).

for column G, its the same issue. {=SUM(IF(FREQUENCY(IF('Table 1'!$F$2:$F$353=$H2,MATCH('Table 1'!$B$2:$B$353,'Table 1'!$B$2:$B$353,0)),ROW('Table 1'!$B$2:$B$353)-ROW('Table 1'!B2)+1),1))}

How can I get an accurate count of all items (column F) and unique items (column G) when the date/time crosses midnight.

For the highlighted example on Route Breakdown tab the answer for F3 should be 19(not 10) and G3 should be 7(not 5).

Thanks for your time in advance. Example w Formulas.xlsx

p.s. on a side note, when running my VBA script the Frequency formula above takes a huge % of the total macro time. I have a spreadsheet which runs whole VBA script in 52seconds but 36seconds of it is that is the one formula being calculated. Is use of Frequency a huge excel processor suck?