Query for average without counting zeros

I have a string in my form like this.

Sub SumAsking_Rent_AVERAGE()
   Me.Asking_Rent_Average = (Nz(Me.Asking_Rent_LOW, 0) + Nz(Me.Asking_Rent_HIGH, 0)) / 2
End Sub

This basically adds two fields and puts the average in the form field.

Now I need to create a query that will add the table column data and give me an average without adding the zeros.  I had to put a default zero in the cell.  Right no my "test" SQL looks like this.


SELECT DISTINCTROW TradeArea.TradeAreaID, Count(*) AS [Count Of Property], Avg(Property.AskingRentAVERAGE) AS AvgOfAskingRentAVERAGE
FROM Property 
GROUP BY TradeArea.TradeAreaID
HAVING (((TradeArea.TradeAreaID)=1));

Open in new window

napsternovaDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carsRSTCommented:
SELECT DISTINCTROW TradeArea.TradeAreaID, Count(*) AS [Count Of Property], Avg(Property.AskingRentAVERAGE) AS AvgOfAskingRentAVERAGE
FROM Property
GROUP BY TradeArea.TradeAreaID
HAVING TradeArea.TradeAreaID=1 and Avg(Property.AskingRentAVERAGE) >0
0
Rey Obrero (Capricorn1)Commented:
try this

SELECT Sum(Property.AskingRentAVERAGE) AS TSum, Sum(IIf([AskingRentAVERAGE]>0,1,0)) AS vCount, [Tsum]/[vCount] AS Average
FROM Property
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
napsternovaDeveloperAuthor Commented:
I tried that but I am getting crazy small numbers for my average.  I should have an average of $25 but am getting $1.32.  It is dividing by the row count.  In the database itself if I filter out the zeros I get the correct average. ??
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Rey Obrero (Capricorn1)Commented:
which query are you referring to?
0
carsRSTCommented:
Might try this....

SELECT TradeArea.TradeAreaID, Count(*) AS [Count Of Property], Avg(Property.AskingRentAVERAGE) AS AvgOfAskingRentAVERAGE
FROM
(
SELECT * FROM Property where AskingRentAVERAGE <> 0 as table1)

)
where TradeAreaID=1
GROUP BY TradeArea.TradeAreaID
0
napsternovaDeveloperAuthor Commented:
Sorry for the confusion.  Capricorn must have submitted as I was typing.  I was referring to the first response by carsRST.  I will try both of your solutions. Thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.