Mysql: Count, Group By, and limiting to first instance of an ID
It takes 2 steps:

SELECT  user_id, COUNT(DISTINCT contact_id) AS 'count'
    FROM  
    (
        SELECT  i.contact_id, MIN(a.user_id) AS user_id
            FROM  activities AS a
            JOIN  invoices AS i  ON i.id = a.post_id
            GROUP BY  i.contact_id 
    ) x
    GROUP BY  x.user_id;


(Possibly the DISTINCT can be removed.)