On what platform are you running this? I see several things in the script which are not supported in SQL Server: date_trunc, months as argument to datetime, "GROUP BY 1, 2, 3".
Oh, I see now that you have use both tags for SQL Server and Postgres. Unfortunately, I cannot test on Postgres right now.
However, while working with your script, I noticed that you have a table priofile_users. Is that name correct? Or should that be profile_users without an extra i?
Also, I note that your final query refers to a column, first_table.total_assistance, but the CTE does not define this column.