MS Access: How can I average a list of quantities on a report where the quantities are not zero?

a 夏天 提交于 2019-12-11 05:39:13

问题


I have a report. This reports returns a lot of rows. One of the columns is qty_req (quantity required). I need to AVG() this column and put the value of the average at the bottom of the report. The problem is that sometimes some rows have a zero in this column. I want the average to exclude any rows where there is a zero. How can I accomplish this?

What I've tried: I tried using DAvg in the query but it made the query time enormous.


回答1:


Avg() ignores Null values. So you can use an IIf() expression to swap Null for your zero values, and then base the Avg() on that IIf() expression.

Here is the Control Source for a text box in my report's footer:

=Avg(IIf([gainOrLoss]=0, Null, [gainOrLoss]))

gainOrLoss is a field in the report's Record Source. And the text box displays the average of all those values which are neither zero nor Null.




回答2:


Well then you can't use a calculated SUM() or AVG() field, simple as that.
These functions always use all rows in the report.

You need DSum() or DAvg() to calculate it separately.

If that's too slow, you need to tackle this problem.



来源:https://stackoverflow.com/questions/38744454/ms-access-how-can-i-average-a-list-of-quantities-on-a-report-where-the-quantiti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!