10

Need help with a SOQL Query. We are trying to pull our highest sales records by month and user. Looking to see something like: "John Doe 100 Sales May 2014. Currently I am getting the calendar month, but not the year. Below is what I have currently, any suggestions are appreciated!

SELECT Count(Id), Sold_By__r.Name, calendar_month(Sold_By_Date__c) 
FROM Case 
WHERE Status = 'Sold' 
AND Sold_By__c !='005U0000000aL0BIAU' 
AND Sold_By__c !=''  
GROUP BY Sold_By__r.Name, calendar_month(Sold_By_Date__c) 
ORDER BY Count(Id) DESC 
LIMIT 10
14

You can also use the CALENDAR_YEAR(Sold_By_Date__c) to pull out the year part of the data

SELECT Count(Id), Sold_By__r.Name, calendar_year(Sold_By_Date__c), calendar_month(Sold_By_Date__c) 
FROM Case 
WHERE Status = 'Sold' 
AND Sold_By__c !='005U0000000aL0BIAU' 
AND Sold_By__c !=''  
GROUP BY Sold_By__r.Name, calendar_year(Sold_By_Date__c), calendar_month(Sold_By_Date__c) 
ORDER BY Count(Id) DESC 
LIMIT 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.