Getting Distinct ID Count based on the date range
- SELECT
- "Opportunities.Entity",
- count(DISTINCT("Opportunities.Id")) AS 'Total Opportunities',
- if(MONTH("Opportunities.Created Time") = Month(Now() - 1), count(DISTINCT("Opportunities.Id")), '0' ),
- count_if(MONTH("Opportunities.Created Time") = Month(Now()) - 1) as 'Opportunities Last Month',
- count_if(("Opportunities.Stage" = 'Deal Won')
- AND ("Opportunities.Deal Type" = 'New Deal')
- AND (MONTH("Opportunities.Closing Date") = Month(Now()) - 1)) As 'Deal Won Last Month',
- ((count_if(("Opportunities.Stage" = 'Deal Won')
- AND (MONTH("Opportunities.Closing Date") = Month(Now()) - 1)
- AND (("Opportunities.Deal Type" = 'New Deal')))) / count_if((Month("Opportunities.Created Time") = (Month(Now()) -1)))) * 100 AS "Conversion Ratio",
- sum_if(((MONTH("Opportunities.Closing Date")) = ((month(now())) -1))
- AND ("Opportunities.Deal Type" = 'New Deal')
- AND ("Opportunities.Stage" = 'Deal Won'), "Opportunities.Actual Booking Amount") AS "Actual Booking Amount",
- avg_if(((MONTH("Opportunities.Closing Date")) = ((month(now())) -1))
- AND ("Opportunities.Deal Type" = 'New Deal'), "Opportunities.Actual Booking Amount") AS "Average Booking Amount",
- sum_if(("Opportunities.Stage" = 'Deal Won')
- AND ("Opportunities.Deal Type" = 'New Deal')
- AND (Month("Payment Collection Info (Clubbed Duplicate OPP ID).Collection Date")) = ((month(now())) -1), "Payment Collection Info (Clubbed Duplicate OPP ID).Collection Amount") AS 'Collection Amount',
- count_if(("Payment Collection Info (Clubbed Duplicate OPP ID).Collection Amount" > 0)
- AND (Month("Payment Collection Info (Clubbed Duplicate OPP ID).Collection Date")) = ((month(now())) -1)
- AND ("Opportunities.Stage" = 'Deal Won')
- AND ("Opportunities.Deal Type" = 'New Deal')) AS "No of orders (collection)",
- sum_if((Month("Opportunities.Closing Date")) = ((month(now())) -1)
- AND ("Opportunities.Stage" = 'Deal Won')
- AND ("Opportunities.Deal Type" = 'New Deal'), "Opportunities.Pending Collection") as 'Pending Collection'
- FROM "Opp+paymentinfo+users"
- GROUP BY "Opportunities.Entity" /* This is a sample SQL SELECT Query */
- /*Use "Control + Space Bar" to see other keywords*/
Query Error: Improper usage of GROUP BY clause.
Please ensure that all non-aggregate columns used in the SELECT clause are also used in GROUP BY clause.
I am trying to count the distinct Opportunities.Id based on the month however I am stuck at this.
if(MONTH("Opportunities.Created Time") = Month(Now() - 1), count(DISTINCT("Opportunities.Id")), '0' ) --- Line 4
Any inputs appreciated.