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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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.