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

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?
LVL 1
###### Who is Participating?

x

Commented:
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

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

Author Commented:
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

Author Commented:
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

Commented:
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

Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.