Assuming all shift data is ordered as it is in the example, you could add a helper column to indicate next AM clocking out for the same shift. For example enter in I3
and fill-down:
=(A2 = A3) * (B2 = B3) * (C2 = C3) * (D2 + 1 = D3) * (G2 = "PM") * (G3 = "AM")
Then in Productivity:
=COUNTIFS('Days Worked'!A:A, ">=" & A2, 'Days Worked'!A:A, "<=" & B2, 'Days Worked'!B:B, D2, 'Days Worked'!C:C, E2,
'Days Worked'!I:I, "<>1")
Please let me know if you have Excel for Microsoft 365, then I could update the answer with dynamic array formulas.