In Access VBA expression builder, how do I sum a column conditionally?
-
14-04-2021 - |
Question
Let's say I have two fields A
and B
and one textbox B_input
. I would like to set up a query so it sums all entries of column A
where B = B_input
Currently I have:
==Sum(IIf([B_input]<>"All",[A],IIf([B_input]<>[B],0,[A])))
I did more testing, it seem the problem is that under Sum(IIF([B_input])), it's not recognizing the value of [B_input], but if I just have IIF([B_input]), it recognize the value just fine, any ideas?
Solution 3
Gave up, went with form filtering instead.
OTHER TIPS
iif([B_input]=="xyz",Sum[A],False)
Might be what you're after but I'm not sure i understood your question properly.
Alternatively, just edit the sql to something like
SELECT(SUM[A]) AS SumOfA FROM [MyTable] HAVING ("B"="xyz");
How about:
=Sum(IIf([B_input]<>"All",[A],0))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow