Question: I want to get counts of subscribers who terminate and re-enroll in the same month when the Termination reason is 'xxx' for past 12 months in a row.

![Example](https://i.stack.imgur.com/DI93M.png)

In the above example, subscriber '1245' has been terminated for 'xxx' reason but re-enrolled again in the same month. I want counts of how many times this happens month by month for last n number of months.

I tried below code to get PersonIDs but having trouble getting counts in a month.

```
SELECT DISTINCT PersonID FROM Membership A

INNER JOIN (SELECT StartYrMo FROM Membership) B

ON A.EndYrMo = B.StartYrMo

WHERE A.TermReason = 'xxx'

ORDER BY PersonID

```

**EDIT** There is more to it. I want all the PersonIds who does so for at least 6 months in a row. Meaning: Person 'A' is terminated due to 'xxx' reason in 201901. 'A' is again terminated due to same 'xxx' reason in 201902 through 201908 which is minimum of 6 months. I want Ids of everyone who does this.

Answer: 
Check the expression you're using: `print(list(s_matrix[0]))`. I think you'll find that it's a double-nested list

```
[[79 75 33 26]]

```

Thus, the "sum" is merely concatenation of a single list element.
sum\_test = reduce((lambda a,b : a+b), list(s\_matrix[0]))

above line is your problem,

you are only giving the first row of your matrix instead of giving the whole matrix