What you're trying to achieve
is a variation on a common theme called
'Moving Window Count Distinct'.
For a great deal of discussion,
please refer to this (epic) thread :
I've intentionally referenced (above) the reply by Joe Mako,
since other ideas are revolving around his solution.
Please find in the attached a modification of the above.
Hope it could help (feeling a complexity of this case).
Moving_CountD_by_Period_YF.twbx 13.4 KB