COQL for SUM and COUNT

COQL for SUM and COUNT

I just can't get the syntax correct on this and could do with some help. I've looked through all the posts and dcumentation I can find, however a lot of it is contradictory.

I am wanting to essentially duplicate this Analytics agregate formula in a CRM function:
  1. count_if(("Opportunities"."Stage" = 'Committed, not Signed') OR ("Opportunities"."Stage" = 'In Quotation (Awaiting Proposal)') OR ("Opportunities"."Stage" = 'In Quotation (Awaiting Response)') OR ("Opportunities"."Stage" = 'In Quotation (Clarify Requirements)'))

I have set up a connection in the CRM for OAuth in Developer Space > Connections


This function works as I would expect :
  1. payload = {"select_query":"SELECT Total_Amount FROM Deals WHERE ((Stage = 'Committed, not Signed') or (Stage = 'In Quotation (Awaiting Proposal)')) or ((Stage = 'In Quotation (Awaiting Response)') or (Stage = 'In Quotation (Clarify Requirements)'))"};
  2. response = invokeurl
  3. [
  4.     url :"https://www.zohoapis.eu/crm/v2/coql"
  5.     type :POST
  6.     parameters:payload.toString()
  7.     connection:"zohocrmcoql"
  8. ];
  9. info response;
  10. return response;
However I can't seem to count the records no matter how I format. I'm also looking to sum a field called Total_Amount as well...

Even trying a simpler query doesn't seem to work :
  1. payload = {"select_query":"select SUM(Total_Amount), Stage from Deals where Stage = 'Committed, not Signed' group by Stage"};
  2. response = invokeurl
  3. [
  4.     url :"https://www.zohoapis.eu/crm/v2/coql"
  5.     type :POST
  6.     parameters:payload.toString()
  7.     connection:"zohocrmcoql"
  8. ];
  9. info response;
  10. return response;
Gives me this
Function executed successfully
{"code":"INVALID_QUERY","details":{"clause":"group by","column_name":"SUM(Total_Amount)"},"message":"select column should be given in group by clause","status":"error"}

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now