sql server – Count only new people added to payroll based on previous month

;WITH x AS 
(
  SELECT m = CONVERT(date, PaymentMonth + '01'), PersonID
  FROM dbo.(table)
  -- WHERE PaymentMonth >= '202105'
  GROUP BY PaymentMonth, PersonID
),
y AS 
(
  SELECT m, PersonID, 
    c    = COUNT(*) OVER (PARTITION BY m),
    rn   = DENSE_RANK() OVER (ORDER BY m),
    prev = LAG(m, 1) OVER (PARTITION BY PersonID ORDER BY m)
  FROM x
),
z AS 
(
  SELECT m, c, 
         dif = COALESCE(c-LAG(c,1) OVER (ORDER BY m),0),
         new = CASE WHEN rn = 1 OR prev = DATEADD(MONTH,-1,m) THEN 0 ELSE 1 END
  FROM y
)
SELECT PaymentMonth  = m, 
       CountPersons  = c, 
       MoMDifference = SUM(dif), 
       NewlyAdded    = SUM(new)
FROM z 
GROUP BY m, c
ORDER BY m;

Given the sample data (plus a few duplicates you don’t want to count), the output is as follows:

PaymentMonth  CountPersons  MoMDifference  NewlyAdded
------------  ------------  -------------  ----------
2021-05-01    4             0              0
2021-06-01    5             1              1
2021-07-01    6             1              3
2021-08-01    6             0              3

fiddle