Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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