SOQL query for multilevel grouping on Engagement Activities Object fails with Error

I have created a custom object Engagement Activities which has lookup fields to Account and Contact objects. I have loaded data in Engagement Activities object. I want to know how many contacts are linked to an account in Engagement Activities object. I have formed following query to get the count of contacts against an account in Engagement activities object but query fails with MALFORMED QUERY error. I have tried various options available in SOQL but unable to get count of contacts

Can someone help me to know if this is limitation of SOQL?

select account__c,contact__c,count(contact__c) 
from engagement_Activities__c 
group by rollup (account__c,contact__c)

Read more here: Source link