Solved

Exclude Amounts from Total based on another field content in report

Posted on 2011-09-27
6
198 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

912 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

22 Experts available now in Live!

Get 1:1 Help Now