Question : Calculating Averages

I have a report that displays averages of columns in a table.  The SQL below is not coming up with just one average for each column, instead multiple rows for each column (see screenshot below - shows you the dataset that comes back from the SQL).  I would expect 1 row to come back with an average for each column.  

====================

Dim dbs As Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim rstComments As DAO.Recordset
   
Set dbs = CurrentDb
   
strSQL = "SELECT Avg(tblComments.intProfessional) AS AvgOfintProfessional, Avg(tblComments.intSpeed) AS AvgOfintSpeed, Avg(tblComments.intFriendliness) AS AvgOfintFriendliness, Avg(tblComments.intKnowledge) AS AvgOfintKnowledge, Avg(tblComments.intVariety) AS AvgOfintVariety, Avg(tblComments.intQuality) AS AvgOfintQuality, Avg(tblComments.intPresentation) AS AvgOfintPresentation, Avg(tblComments.intBeverage) AS AvgOfintBeverage, Avg(tblComments.intAtmosphere) AS AvgOfintAtmosphere, Avg(tblComments.intValue) AS AvgOfintValue, Avg(tblComments.intOverallExperience) AS AvgOfintOverallExperience FROM tblComments " _
& "GROUP BY tblComments.datCommentDate, tblComments.intVenueID HAVING (((Avg(tblComments.intProfessional))<>0) AND ((Avg(tblComments.intSpeed))<>0) AND ((Avg(tblComments.intFriendliness))<>0) AND ((Avg(tblComments.intKnowledge))<>0) AND ((Avg(tblComments.intVariety))<>0) AND ((Avg(tblComments.intQuality))<>0) AND ((Avg(tblComments.intPresentation))<>0) AND ((Avg(tblComments.intBeverage))<>0) AND ((Avg(tblComments.intAtmosphere))<>0) AND ((Avg(tblComments.intValue))<>0) AND ((Avg(tblComments.intOverallExperience))<>0) AND ((tblComments.datCommentDate) Between [Forms]![frmVenueSpecification]![txtfromdate] And [Forms]![frmVenueSpecification]![txttodate]) AND ((tblComments.intVenueID) Like [Forms]![frmVenueSpecification]![txtvenue]));"

Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Parameters("[Forms]![frmVenueSpecification]![txtfromdate]") = Forms!frmVenueSpecification!txtFromDate
qdf.Parameters("[Forms]![frmVenueSpecification]![txttodate]") = Forms!frmVenueSpecification!txtToDate
qdf.Parameters("[Forms]![frmVenueSpecification]![txtvenue]") = Forms!frmVenueSpecification!txtVenue

Set rstComments = qdf.OpenRecordset

Me.txtProfAvg.Value = Round(rstComments![AvgOfintProfessional], 2)
Me.txtSpeeAvg.Value = Round(rstComments![AvgOfintSpeed], 2)
Me.txtFrieAvg.Value = Round(rstComments![AvgOfintFriendliness], 2)
Me.txtKnowAvg.Value = Round(rstComments![AvgOfintKnowledge], 2)
Me.txtVariAvg.Value = Round(rstComments![AvgOfintVariety], 2)
Me.txtQualAvg.Value = Round(rstComments![AvgOfintQuality], 2)
Me.txtPresAvg.Value = Round(rstComments![AvgOfintPresentation], 2)
Me.txtBeveAvg.Value = Round(rstComments![AvgOfintBeverage], 2)
Me.txtAtmoAvg.Value = Round(rstComments![AvgOfintAtmosphere], 2)
Me.txtValuAvg.Value = Round(rstComments![AvgOfintValue], 2)
Me.txtExpeAvg.Value = Round(rstComments![AvgOfintOverallExperience], 2)

====================

Could it be because I'm not including data that has 0s that it's messing it up?

What would the SQL be to get the average for each of these columns?
Attachments:
 
results from sql
results from sql
 

Answer : Calculating Averages

Your problem is the GROUP BY clause.  Try:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
strSQL = "SELECT Avg(intProfessional) AS AvgOfintProfessional, Avg(intSpeed) AS AvgOfintSpeed, " & _
    "Avg(intFriendliness) AS AvgOfintFriendliness, Avg(intKnowledge) AS AvgOfintKnowledge, " & _
    "Avg(intVariety) AS AvgOfintVariety, Avg(intQuality) AS AvgOfintQuality, " & _
    "Avg(intPresentation) AS AvgOfintPresentation, Avg(intBeverage) AS AvgOfintBeverage, " & _
    "Avg(intAtmosphere) AS AvgOfintAtmosphere, Avg(intValue) AS AvgOfintValue, " & _
    "Avg(intOverallExperience) AS AvgOfintOverallExperience " & _
    "FROM tblComments " & _
    "WHERE (datCommentDate Between [Forms]![frmVenueSpecification]![txtfromdate] And " & _
    "[Forms]![frmVenueSpecification]![txttodate]) AND " & _
    "intVenueID Like [Forms]![frmVenueSpecification]![txtvenue]) "
    "HAVING Avg(intProfessional)<>0 AND Avg(intSpeed)<>0 AND Avg(intFriendliness)<>0 AND " & _
    "Avg(intKnowledge)<>0 AND Avg(intVariety)<>0 AND Avg(intQuality)<>0 AND " & _
    "Avg(intPresentation)<>0 AND Avg(intBeverage)<>0 AND Avg(intAtmosphere)<>0 AND " & _
    "Avg(intValue)<>0 AND Avg(intOverallExperience)<>0"
Random Solutions  
 
programming4us programming4us