473,832 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating values from subreports when one or more is null

52 New Member
I found something similar, but can't get it to work--maybe because I'm working in a report rather than a query?

I have a main report that has three subreports in it. Each subreport has a total for items in that subreport. If all three have entries, I can get a grand total, but if one or more doesn't, it just says error. I first tried using IIf/IsNull, but again, I get totals only when all three subreports have amounts. I then found nz, and tried that, but still I only get a total when all three have values. This seems like it just shouldn't be that complicated.

Here's what I have:

Expand|Select|Wrap|Line Numbers
  1. =Nz([Reports]![Final Bid Sheets]![Final Bid Sheet Auction Items subreport]![Auction Total])+Nz([Reports]![Final Bid Sheets]![Final Bid Sheet Party 1 subreport]![Party1 total])+Nz([Reports]![Final Bid Sheets]![Final Bid Sheet Party 2 subreport]![Party2 total]) 
Can anyone tell me what I'm doing wrong? Or if there is an easier way of doing this? Thanks so much.
Jan 8 '08
28 3684
Rabbit
12,516 Recognized Expert Moderator MVP
I misunderstood the original circumstances, use iif() in conjunction with IsError()

Expand|Select|Wrap|Line Numbers
  1. =iif(IsError(Reports!MainReport!SubReport!Control), 0, Reports!MainReport!SubReport!Control)
  2.  
You may or may not need to use Nz, Sum, Val in conjunction with this as well.
Jan 9 '08 #11
CindySue
52 New Member
I may be getting closer. I tried the suggestions by Rabbit and by Puppydogbuddy, but I get 0 for every single total, however,I may have discovered what part of my problem is (or not!). Auction Total is the name of the control that adds up the Winning Bid Amount field in the Auction Items subreport. Party1 total and Party2 total are the names of the controls that add up the amount field in the Party 1 and Party 2 subreports. When I substituted the names of the actual fields (Winning Bid Amount, Amount and Amount) into Rabbits code, it begins to work somewhat. It adds up the last item in each of the subreports. For example, if there are two auction items for $10 each, two Party 1 for $20 and two Party 2 for $30, the total is $60--adding up the last 10, 20 and 30. I've been trying to work the sum around my code to see if that will cause it to add all the totals, but I can't seem to get that right. Am I on track that the problem is that my code was using control names rather than field names, or was this just a wild tangent that gained me no ground?

Anyway, here's my code now:
Expand|Select|Wrap|Line Numbers
  1. =IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![Winning Bid Amount]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![Winning Bid Amount])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![Amount]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![Amount])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![Amount]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![Amount])
And I really appreciate all the help! I'm doing this for a charity.

I have been trying these in all sections (detail, group footer, page footer and report footer) by the way. Is there a particular section they must go in?
Jan 9 '08 #12
Rabbit
12,516 Recognized Expert Moderator MVP
Calculate the sum in a control on the subforms and then call that control from the main form.
Jan 9 '08 #13
puppydogbuddy
1,923 Recognized Expert Top Contributor
CindySue,
To answer your question, "Am I on track that the problem is that my code was using control names rather than field names, or was this just a wild tangent that gained me no ground?"

The answer is yes, you should be referring to the control source, not the control name when you are processing totals. Summing the control source picks up all the detail lines, while summing the control name picks up just the first detail. That explains why the earlier formulas you had did not work. If you plug the Control Source into the code I gave you or the code Rabbit gave you, it should work, provided that your totals are in the subreport header or footer. Totals in the headers or footers must contain the equal sign and Sum keyword. The detail lines reference the control source without use of the equal sign or Sum keyword.

Hope this helps.
Jan 9 '08 #14
CindySue
52 New Member
I'm completely confused. I guess I don't know what the control name is, then. I have a text box on the subreport that creates the total, and it shows up on in the subreport inside the main report with the correct total for all records. When I click on the right side of that control in the subreport and go to properties, under name it says Auction Total. I thought that was the Control Name. But when I substitute those names (Auction Total, Party1 total and Party2 total) in the code in place of the field names (Winning Bid Amount, Amount and Amount) I get #Error.
Jan 9 '08 #15
puppydogbuddy
1,923 Recognized Expert Top Contributor
I'm completely confused. I guess I don't know what the control name is, then. I have a text box on the subreport that creates the total, and it shows up on in the subreport inside the main report with the correct total for all records. When I click on the right side of that control in the subreport and go to properties, under name it says Auction Total. I thought that was the Control Name. But when I substitute those names (Auction Total, Party1 total and Party2 total) in the code in place of the field names (Winning Bid Amount, Amount and Amount) I get #Error.
Name is control name
Control source is the property just below the name. The control source is what you should be using in the summations
Jan 9 '08 #16
puppydogbuddy
1,923 Recognized Expert Top Contributor
Name is control name
Control source is the property just below the name. The control source is what you should be using in the summations
Let me clarify
use control source when summing a column of numbers
use name when referencing a control that has a summaton and you want to pick up the result of the calculated control.

see this link:
http://allenbrowne.com/casu-18.html
Jan 9 '08 #17
CindySue
52 New Member
So I replaced
[Auction Total] with [=sum([Winning Bid Amount])]
[Party1 Total] with [=sum(Amount)]
[Party2 Total] with [=sum(Amount)]
in my code and I get "The expression you entered contains invalid syntax."

I also tried leaving out the = sign, but got the same error. My code is now:
Expand|Select|Wrap|Line Numbers
  1.  
  2. =Val(Sum(Nz(IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![=sum([Winning Bid Amount])]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![=sum([Winning Bid Amount])])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![=sum(Amount)]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![=sum(Amount)])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![=sum(Amount)]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![=sum(Amount)])))) 
  3.  
I'm almost ready to take an adding machine and hand write in the totals at this point. This just doesn't seem like it should be so hard.
Jan 9 '08 #18
puppydogbuddy
1,923 Recognized Expert Top Contributor
So I replaced
[Auction Total] with [=sum([Winning Bid Amount])]
[Party1 Total] with [=sum(Amount)]
[Party2 Total] with [=sum(Amount)]
in my code and I get "The expression you entered contains invalid syntax."

I also tried leaving out the = sign, but got the same error. My code is now:
Expand|Select|Wrap|Line Numbers
  1.  
  2. =Val(Sum(Nz(IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![=sum([Winning Bid Amount])]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![=sum([Winning Bid Amount])])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![=sum(Amount)]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![=sum(Amount)])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![=sum(Amount)]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![=sum(Amount)])))) 
  3.  
I'm almost ready to take an adding machine and hand write in the totals at this point. This just doesn't seem like it should be so hard.

CindySue,
where did this syntax come from?

change this:
[quote=CindySue]So I replaced
[Auction Total] with [=sum([Winning Bid Amount])]
[Party1 Total] with [=sum(Amount)]
[Party2 Total] with [=sum(Amount)]

to this:

[Auction Total] with =sum([Winning Bid Amount])
[Party1 Total] with =sum([Amount])
[Party2 Total] with =sum([Amount])
Jan 9 '08 #19
CindySue
52 New Member
I was working on my response before I saw your clarification. When you stated "Name is control name. Control source is the property just below the name. The control source is what you should be using in the summations" I took that to mean that I should be using the line below the name which says Control Source in place of the names that I had been using in my calculations, so I substituted what was in Control Source for the name--hence [Auction total] became [=sum([Winning Bid Amount])], etc. I read in your clarification that I should be using the names, so back to [Auction total] the "Name" on the property sheet and my code looks like this:

Expand|Select|Wrap|Line Numbers
  1. =Val(Sum(Nz(IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![Auction Total]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Auction Items subreport]![Auction Total])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![Party1 total]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 1 subreport]![Party1 total])+IIf(IsError([Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![Party2 total]),0,[Reports]![Final Bid Sheets]![Final bid Sheet Party 2 subreport]![Party2 total]))))
which just gives me #Error.
I think I just figured out how to include a file, if that helps.
Attached Images
File Type: jpg screenshot.jpg (35.3 KB, 278 views)
Jan 9 '08 #20

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

Similar topics

2
47858
by: Shaun | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Time and Booking_End_Time. These columns are both of type DATETIME. Given any day how can I calculate how many hours are available between the hours of 09.00 and 17.30 so a user can see at a glance how many hours they have unbooked on a particular day (i.e. 8.5 hours less the time of any bookings on that day), can this be done with a query or do I have to...
0
2277
by: Kasp | last post by:
Hi there, I am trying to make an OLAP cube on a table having two columns (datetime, Number_of_times_an_event_occured). My dimension is time and I want to measure the Min and Max times an event occured over time. I have no problem in calculating Maximum occurance of events over time. However, I have some NULL values in my Number_of_times_an_event_occured column, due to which I don't see any result when I try to calculate
3
12827
by: Phil Sandler | last post by:
All, I have a table with start and end dates/times in it, and would like to be able to calculate the number of hours represented, accounting for overlapping records. Note that I am looking for an answer on HOW to do this--I don't necessarily need it to be written for me (although it would not go unappreciated!).
1
3248
by: Robin Munn | last post by:
I'm trying to calculate the default values of a column when I insert a row, based on the values of other columns. It's something I thought should be simple enough, but I can't seem to figure out how to do it. Here's a basic example of what I'm trying to do: CREATE TABLE money ( amount numeric NOT NULL, currency text NOT NULL DEFAULT 'USD', currency_per_usd numeric NOT NULL DEFAULT 1.00, usd_amount NOT NULL DEFAULT (amount /...
1
2513
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than less. i tried to delineate certain areas so that it would be easy to peruse my posting and find...
1
2133
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from those dates. I have learned how to use this start/end function but I can't figure out how to use it with these subreports. Right now the report opens but asks for start/end dates for each of the five reports. Is there a way I can input one set of...
1
2472
by: josecruz | last post by:
I have created a main report, which is controlled with a date range parameter from the main form. The report has several sub reports, which perform calculations (counts and averages at the subreport level) based on the date range from the main form. My question or problem is that I have to calculate a percentage based on the result of two of the subreports. I created a text box on the main report and I enterd the following to calculate the...
3
1732
by: DeanL | last post by:
Hi all, I'm currently pulling out my already thin hair and need a little help if possible. I have an Access 97 db that is used to store inspection information for different regions. My report is meant to show the number of inspections done in each region and what ratings they achieved as below: Region Green Yellow Red NR Total
6
5460
by: Brett Barry: Go Get Geek! | last post by:
Hello, I have a main report with a Record Source, a DateToday table, that has the current Month and Year. I have about 60 queries, each pulling different data via ODBC, that I am creating subreports that go on the main report. The problem is that when I run the report the data shows on the screen but not the print preview. I am aware that the main report is not linked to the subreports because of the Link Master, Child Fields issue....
0
9796
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10500
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10543
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9323
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.