function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ramya BalakrishnanRamya Balakrishnan 

SOQL query for current and previous year sales by product.

I have a requirement for creating Data table LWC component. the component look like the following format.User-added image
I have written the following  query for getting data from salesforce for this table.

SELECT  Product__c ,COUNT(Quantity__c), 
    SUM(CASE
 WHEN invoice_date = CALENDAR_YEAR(system.today()) THEN 
             Total_Price__c
             ELSE 0 
           END) AS "This year Sales" ,
   SUM( CASE
 WHEN invoice_date = CALENDAR_YEAR(system.today()) - 1 THEN 
             Total_Price__c
             ELSE 0 
           END) AS "Last year Sales" 
 FROM Invoice_Lines__c GROUP BY Invoice_Lines__c.Product__c

I am getting 'Unknown error query parsing'  error. If i remove the case statements , the query runs without any error. i am not able to figure out the issue with the case statements.
Can anybody suggest how to solve this error or is there any other way i can modify the query? i need a single query to pass the records to the datatable component.

Thanks
Ramya Balakrishnan
SwethaSwetha (Salesforce Developers) 
HI Ramya,
Where are you running this SOQL? Does it show this error even in developer console/ Workbench with CASE included?
Thanks
Ramya BalakrishnanRamya Balakrishnan
Hi Swetha
   Thanks for responding. I am running this SOQL in Developer Console only.  Error is in the developer console only.

Thanks
Ramya Balakrishnan