I need help with this query. It returns me with 3 groups: Closed, Waiting and In progress. However I want to combine the Waiting and In progress groups to see the Closed vs not closed. How can I do this, this is the query I have now.

select Status,count(CaseNumber) number from Case where Quelle__c = 'Nutzer' and 
(CreatedDate = THIS_QUARTER or ClosedDate = THIS_QUARTER) GROUP BY Status

1 Answer 1


One way is to use Apex code:

Integer notClosed = 0;
Integer closed = 0;
for (AggregateResult ar : [...]) {
    String s = (String) ar.get('Status');
    Integer n = (Integer) ar.get('number');
    if (s != 'Closed') {
         notClosed += n;
    } else {
         closed += n;


Also there is also the IsClosed field on Case:

select IsClosed, count(Id) number from Case group by IsClosed

and you can configure the statuses this corresponds to in the status field setup.

  • Thank you for your answer. It is just not what I am looking for. I really need it in SOQL.
    – Martijn
    Jul 13, 2015 at 9:19
  • @Martijn See the PS.
    – Keith C
    Jul 13, 2015 at 9:51
  • That did it. Thank you. 1 more thing, is there any way I can name the groups? So it wont say True / Unknown.
    – Martijn
    Jul 13, 2015 at 10:27
  • @Martijn You could add a formula field based on IsClosed to Case containing a friendlier name and group by that.
    – Keith C
    Jul 13, 2015 at 10:30
  • I can't figure out how to do that. But thank you!
    – Martijn
    Jul 13, 2015 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .