You should use query entity with aggregation as has been suggested. However, in the interests of answering the question, here's some sample code that uses union(), a!forEach() and wherecontains() to do a group by and sum across a dictionary - hope it…