Getting Distinct ID Count based on the date range

Getting Distinct ID Count based on the date range

  1. SELECT
  2.  "Opportunities.Entity",
  3.  count(DISTINCT("Opportunities.Id")) AS 'Total Opportunities',
  4.  if(MONTH("Opportunities.Created Time")  = Month(Now() - 1), count(DISTINCT("Opportunities.Id")), '0' ),
  5.  count_if(MONTH("Opportunities.Created Time")  = Month(Now()) - 1) as 'Opportunities Last Month',
  6.  count_if(("Opportunities.Stage"  = 'Deal Won')
  7.  AND ("Opportunities.Deal Type"  = 'New Deal')
  8.  AND (MONTH("Opportunities.Closing Date")  = Month(Now()) - 1)) As 'Deal Won Last Month',
  9.  ((count_if(("Opportunities.Stage"  = 'Deal Won')
  10.  AND (MONTH("Opportunities.Closing Date")  = Month(Now()) - 1)
  11.  AND (("Opportunities.Deal Type"  = 'New Deal')))) / count_if((Month("Opportunities.Created Time")  = (Month(Now()) -1)))) * 100 AS "Conversion Ratio",
  12.  sum_if(((MONTH("Opportunities.Closing Date"))  = ((month(now())) -1))
  13.  AND ("Opportunities.Deal Type"  = 'New Deal')
  14.  AND ("Opportunities.Stage"  = 'Deal Won'), "Opportunities.Actual Booking Amount") AS "Actual Booking Amount",
  15.  avg_if(((MONTH("Opportunities.Closing Date"))  = ((month(now())) -1))
  16.  AND ("Opportunities.Deal Type"  = 'New Deal'), "Opportunities.Actual Booking Amount") AS "Average Booking Amount",
  17.  sum_if(("Opportunities.Stage"  = 'Deal Won')
  18.  AND ("Opportunities.Deal Type"  = 'New Deal')
  19.  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',
  20.  count_if(("Payment Collection Info (Clubbed Duplicate OPP ID).Collection Amount"  > 0)
  21.  AND (Month("Payment Collection Info (Clubbed Duplicate OPP ID).Collection Date"))  = ((month(now())) -1)
  22.  AND ("Opportunities.Stage"  = 'Deal Won')
  23.  AND ("Opportunities.Deal Type"  = 'New Deal')) AS "No of orders (collection)",
  24.  sum_if((Month("Opportunities.Closing Date"))  = ((month(now())) -1)
  25.  AND ("Opportunities.Stage"  = 'Deal Won')
  26.  AND ("Opportunities.Deal Type"  = 'New Deal'), "Opportunities.Pending Collection") as 'Pending Collection'
  27. FROM  "Opp+paymentinfo+users" 
  28. GROUP BY  "Opportunities.Entity" /* This is a sample SQL SELECT Query */
  29. /*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.