Solved

# Exclude Amounts from Total based on another field content in report

Posted on 2011-09-27
201 Views
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
Question by:rodneygray
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2

LVL 61

Accepted Solution

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

ID: 36713970
The same approach can be applied to your other field...
0

LVL 1

Author Closing Comment

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

LVL 1

Author Comment

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

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

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

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
###### Suggested Courses
Course of the Month2 days, left to enroll