问题
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