+ Start a Discussion
RovRov 

Count Disticnt Records

I have following records in a list and want a disticnt count. e.g Highlighted records will be counted as 4. Basically there are 4 records under the pcode 'can' that are open since 4 weeks 

id       pcode     NumOfWeeksOpen    
111       can          4    
112       can          4
113       can          4
114       can          4

115       can          14
116       can          24   
117       can          45
118       can          34
119       can          37

Any suggestions?

Thanks!!
120       can          65


                         
Mike @ BlackTabMike @ BlackTab
Inside of a SOQL query just add a COUNT_DISTINCT(NumOfWeeksOpen). 

So something like this:

Integer i = Database.countQuery("SELECT COUNT_DISTINCT(NumOfWeeksOpen) FROM Objectx");


RovRov
Thanks for the response.

I didn't ask the questions correctly.

Basicaly I want count of occurences

id       pcode     NumOfWeeksOpen   
111       can          13  
112       can          13
113       can          4
114       can          4
115       can          27
116       can          27
117       can          27
118       can          34
119       can          37


Occurences of 13 = 2
Occurences of 27 = 3

Occurences of 4 = 2



Count_Distict (NumOfWeeksOpen) will give me Total Count of all Distict records which in this case =  5