I currently have the distinct count of users logging in every day.

I want to add another column to know the distinct count of users logging in at least once for the past 7 days. 

```
;WITH cte (login_date,  years, iso_week, months, emails) AS
(
    SELECT 
        CAST(a.login_time AS Date),
        DATEPART(YEAR, a.login_time),
        DATEPART(ISO_WEEK, a.login_time),
        DATEPART(MONTH, a.login_time),
        COUNT(DISTINCT a.email) AS Total
    FROM 
        database.log AS a WITH(NOLOCK)
    GROUP BY 
        CAST(a.login_time AS Date),
        DATEPART(YEAR, a.login_time),
        DATEPART(ISO_WEEK, a.login_time),
        DATEPART(MONTH, a.login_time)
)

```

Now if I try 

```
SELECT 
    *,
    SUM(emails) OVER (PARTITION BY years, iso_weeks
                      ORDER BY login_date
                      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS counts_week
FROM
    cte

```

This basically adds everyday logins to makeup a week but this is the opposite of what I want. it is not the sum of distinct email logins for 7 days, it is the unique emails who logs in within a week

So if I'm using three emails as example I should have in the column `emails_week` the following

```
+------------+-------+----------+--------+--------+-------------+
| login_date | years | iso_week | months | emails | emails_week |
+------------+-------+----------+--------+--------+-------------+
| 2018-12-07 |  2018 |       49 |     12 |      2 |           2 |
| 2018-12-08 |  2018 |       49 |     12 |      2 |           2 |
| 2018-12-09 |  2018 |       49 |     12 |      1 |           2 |
| 2018-12-10 |  2018 |       50 |     12 |      1 |           3 |
| 2018-12-11 |  2018 |       50 |     12 |      3 |           3 |
| 2018-12-12 |  2018 |       50 |     12 |      1 |           3 |
+------------+-------+----------+--------+--------+-------------+

```