Sum(IIF with a null criteria.....

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
436
Office Version
  1. 2019
Hell all.

I am having an issue with an expression in a query.

What I am trying to do is to sum [Account Balance Total Amount] IF the [External Status Code] is null.

When I use Expr1: Sum(IIf([External Status Code]=" ",[Account Balance Total Amount],0)) I get a zero result

When I use Expr1: Sum(IIf([External Status Code]IsNull,[Account Balance Total Amount],0)) I get Invalid Syntax

When I use Expr1: Sum(IIf([External Status Code],IsNull,[Account Balance Total Amount],0)) I get Wrong Number of Arguments

Thanks for your help.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I would recommend starting off with a simple Select Query.
Add the two fields you have listed. Place "Is Null" in the Criteria row of the "External Status Code" field.
Then, change to an Aggregate Query by clicking on the Totals button (looks like a Sigma).
This will add a "Total Row" to the QBE. Under the "Account Balance Total Amount" field, change the value in that row from "Group By" to "Sum".
That should give you your Total.
 
Upvote 0
SQL could be
Code:
SELECT SUM(name of field to sum) AS [final name of summed field], comma separated list of other fields to return
FROM your_data_source
WHERE [External Status Code] Is Null
GROUP BY comma separated list of other fields to return
 
Upvote 0
Thanks Joe 4. I was just trying to avoid multiple queries when the database is already so large.

I got the answer from another forum. Sum(IIf(IsNull([External Status Code]), [Account Balance Total Amount], 0)) <!-- / message --><!-- Adsense inside first post-->

<!-- / Adsense inside first post--><!-- Adsense inside third post--><!-- / Adsense inside third post--><!-- Adsense inside last post--><!-- / Adsense inside last post--><!-- sig -->
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,104
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top