Solved

Exclude Amounts from Total based on another field content in report

Posted on 2011-09-27
6
197 Views
Last Modified: 2012-08-13
I will keep this simple. I am printing a report. The table used to print the report has 3 fields, pounds, price, and reject reason. Pounds are multiplied by price to arrive at Extended Cost. When printing the report, I total pounds and extended price. However, I need to exclude, from the totals, any record that has reject reason. I still want to print the record. However, it cannot be included in the totals. Could I look at the detail records as they are printing and change the value of any record with a reject reason to text so it will not be included in the total?
0
Comment
Question by:rodneygray
  • 4
  • 2
6 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36713967
You can use a textbox at the bottom (footer section) of your report to do this.  The control source for such a total would be something like this:

= Sum([Pounds] * Abs("" & [RejectReason] = ""))

Use the actual field names as seen in your underlying table or query.

The result is a Sum of Pounds where there is no RejectReason and Zero for records where there is a reject reason.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36713970
The same approach can be applied to your other field...
0
 
LVL 1

Author Closing Comment

by:rodneygray
ID: 36714020
That worked perfectly. However, I cannot figure out what the last part of the formula does. Would you mind explaining it for me (and others)?
= Sum([Pounds] * Abs("" & [RejectReason] = ""))
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:rodneygray
ID: 36714061
I tired the same formula for the extension and the formula does not work. Can you see what I have done wrong?
=Sum([Price]*[pounds])*Abs("" & [RejectReason]="")
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36714083
Sure - that's one of my favorite code tricks.

Explanation -

This is just comparison:

Abs("" & [RejectReason] = "")  = ""

It appends an empty string to RejectReason and compares it to an empty string.  If RejectReason is either Null or empty, the comparison is TRUE.  If it is populated the comparison is FALSE

True = -1  <-- the Abs takes the absolute value, returning 1
False =0

So the value being summed is either Pounds * 1 if the reason field is empty or Pounds * 0 if it is populated.

___

It looks like you've got the idea, but you need another set of parentheses so that you are summing the entire expression:

>> =Sum([Price]*[pounds])*Abs("" & [RejectReason]="")

Should be:

=Sum(([Price]*[pounds])*Abs("" & [RejectReason]="") )



0
 
LVL 61

Expert Comment

by:mbizup
ID: 36714092
An alternative syntax uses IIF, but I like the above method better.  

This is the same thing using IIF:

=Sum(IIF("" & [RejectReason]="", [Price]*[pounds], 0) )


0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now