You can definitely use IIf
within Avg
and get the correct results.
Do you want to exclude the False
values from the calculation entirely?
In your example you're still including them, just setting them to 0
and hence still including them in the calculation. This might explain your unexpected results.
If you want to exclude them entirely use Nothing
instead of 0
.
Edit after comment
You can nest an expression in another IIf
statement and check for NULL values using IsNothing
.
Say your condition average expression is:
=Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing))
You can return 0 for NULL values with something like:
=IIf(IsNothing(Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing)))
, 0.0
, Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing)))