473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sum Nested IIFs in Access 2010

I am trying to sum the following and keep getting either wrong totals or a blank.

=Sum(IIf([Chute#1]="CBOL - N/A",[Pallet#1Lbs]/2000))+(Count(IIf([Chute#2]="CBOL - N/A",[Pallet#2Lbs]/2000)))+(Count(IIf([Chute#3]="CBOL - N/A",[Pallet#3Lbs]/2000)))+(Count(IIf([Chute#4]="CBOL - N/A",[Pallet#4Lbs]/2000)))+(Count(IIf([Chute#5]="CBOL - N/A",[Pallet#5Lbs]/2000)))+(Count(IIf([Chute#6]="CBOL - N/A",[Pallet#6Lbs]/2000)))


Basically, I have a table with 6 fields (Chute#1, Chute#2, etc) that when a record equals "CBOL - N/A" it will SUM the weight stored in another field (Pallet#1Lbs, Pallet#2Lbs, etc.). Is there a better way?
Feb 9 '12 #1

✓ answered by sierra7

Thank goodness for that!

To do the count try copying the 'control' (i.e. the box with the current formula), then change the 'Pallet weight' to 1
Expand|Select|Wrap|Line Numbers
  1. IIf(Chute#1="CBOL - N/A", 1,0) + 
  2.  
The formula should sum the ones and give you your count!
S7

8 3846
Rabbit
12,516 Expert Mod 8TB
You say sum but you use count a lot. Also, all your iif() functions are missing the false parameter. It shouldn't even run, it should be giving you an error.
Feb 9 '12 #2
sierra7
446 Expert 256MB
I don't understand the question. Sometimes you are using SUM and sometimes COUNT.

Are you doing this in a Form or a Report?

Does Pallet#1 correspond only to Chute#1, Pallet#2 to Chute#2 etc. Please confirm.

I think in essence you want the folowing but they are not nested;
Expand|Select|Wrap|Line Numbers
  1. =(
  2. IIf(Chute#1="CBOL - N/A", Pallet#1Lbs,0) +
  3. IIf(Chute#2="CBOL - N/A", Pallet#2Lbs,0) +
  4. IIf(Chute#3="CBOL - N/A", Pallet#3Lbs,0) +
  5. IIf(Chute#4="CBOL - N/A", Pallet#4Lbs,0) +
  6. IIf(Chute#5="CBOL - N/A", Pallet#5Lbs,0) +
  7. IIf(Chute#6="CBOL - N/A", Pallet#6Lbs,0) )/2000
  8.  
I think this is what is you mean but I'm not clear why you used COUNT.
S7
Feb 9 '12 #3
Sorry for the confusion. Yes I had taken out the counts after I posted this question (sorry). I have even added each field (or expression) in increments to test where it stops working. I can get to this point and it calculates fine.

=Sum(IIf([Chute#1]="CBOL - N/A",[Pallet#1Lbs]/2000))+(IIf([Chute#2]="CBOL - N/A",[Pallet#2Lbs]/2000))

But when I add the next field (Chute#3) the results are blank. Based on my data, this is where the first false it should encounter as there is no "CBOL - N/A" in the Chute#3 field.

=Sum(IIf([Chute#1]="CBOL - N/A",[Pallet#1Lbs]/2000))+(IIf([Chute#2]="CBOL - N/A",[Pallet#2Lbs]/2000))+(IIf([Chute#3]="CBOL - N/A",[Pallet#3Lbs]/2000))


Yes, this is in a report. Yes, Pallet#1 field is the weight of Chute#1 and so on. When Chute#1 = "CBOL - N/A" and so on, I want to sum the weights together.
Feb 9 '12 #4
sierra7
446 Expert 256MB
Hi
The IIF() function consists of a 'test', then a value for if the result is true, and then a second value for if the result is false.

The zeros (0) in the code I posted were for when Chute#1 (etc) is not equal to "CBOL - N/A", i.e false. All values must be numeric if you want to add them.

I still can't see why you want to nest the IIF()'s on this occasion and you don't seem to be doing so in your sample code.

A SUM() will only work in the Footer section of a report.

So far I am assuming the are 12 (or more) fields in your table (or query) i.e. 6 Chutes & 6 Weights, one weight per chute. If you are trying to sum multiple weights per chute we have a problem.
S7
Feb 9 '12 #5
@sierra7
---
Your suggestion worked for the weight totals! I put a Sum in front since it was in the footer section and it works like a champ. I assumed that since I used multiple IIFs in the statement that they were "Nested".

Now how can I "Count" the number of times "CBOL - N/A" is listed in all the 6 fields? Can I use the same code and put a count instead of a sum? When I try it returns "0" when there it should return "6".
Feb 9 '12 #6
sierra7
446 Expert 256MB
Thank goodness for that!

To do the count try copying the 'control' (i.e. the box with the current formula), then change the 'Pallet weight' to 1
Expand|Select|Wrap|Line Numbers
  1. IIf(Chute#1="CBOL - N/A", 1,0) + 
  2.  
The formula should sum the ones and give you your count!
S7
Feb 9 '12 #7
Awesome it works! Thanks. It just takes another set of eyes to see through your self-induced confusion.
Feb 9 '12 #8
NeoPa
32,556 Expert Mod 16PB
FYI: IIf() in SQL (which is what you're working with within Control Sources) requires only the first two parameters. The False value, if omitted, defaults to False, which has a numeric value of zero (0) anyway.
Feb 10 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: phill86 | last post by:
Hi, I have an access 2010 database that I want to convert to an SQL Server database and I need to know if the data macros in access will still work in the SQL database or will i have to create...
5
by: jaad | last post by:
Hello, I have a database that was written in access 2007 on my pc. I wanted to work off site with the database so I uploaded it onto my laptop which is loaded with access 2010 beta. When I...
2
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been...
2
by: dougancil | last post by:
I have a user who had deleted some records from a database today using Access 2010. They have an ID field that's autonumbered. They have No Duplicates allowed. When they created a new record today,...
0
by: Andolino | last post by:
In Access 2010 I get a Write Conflict error - "This record has been changed by another user..." In Access 2007 this Code is working - why? Private Sub Form_BeforeUpdate(Cancel As Integer) Dim...
1
by: Alan Yim | last post by:
Hi folks, My company recently upgraded our Office suite from 2003 to 2010. The problem in particular is with an Access database that was originally designed in Access 2003. The code in question...
5
by: colsoft | last post by:
I am using Access 2010. Am generating reports for the records, one record per page. The records on the even pages have a light black background shading which appears when am printing. Please i need...
2
by: Bill Boord | last post by:
I need to be able to shut off the AutoCorrect "feature" within Access 2010 code. I have utilized Application.SetOption with method strings for other startup requirements, but I cannot seem to find a...
1
dsatino
by: dsatino | last post by:
I have numerous applications built in Access 2000/2003 that all use ODBCdirect workspaces to access various non-Access databases. Unfortunately, ODBCdirect is 'no longer supported'in Access 2010 and...
1
by: Music Man | last post by:
Greetings All: I built a database in Microsoft SQL Server 2000 and used Microsoft Access 2010 as the front end. The database is used to keep track of "issues" that rise out of my employment. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.