I'm trying to write the following in order to get a running total of distinct NumUsers
NumUsers = COUNT(DISTINCT [UserAccountKey]) OVER (PARTITION BY [Mth])
There is a very simple solution using
dense_rank() over (partition by [Mth] order by [UserAccountKey]) + dense_rank() over (partition by [Mth] order by [UserAccountKey] desc) - 1
This will give you exactly what you were asking for: The number of distinct UserAccountKeys within each month.