Report values only once

C

CW

I need to analyse and report on our shipments by weight on a monthly basis,
in the month within which they are billed. Trouble is, we often raise more
than one bill per shipment, but I only want to report the weight of each
shipment once.

The weight is held in a Shipments table along with the unique jobref (and
other data).
The billing date is held in the Invoices table along with the jobref and
other data.
There's a one-to-many relationship from Shipments.jobref to Invoices.jobref.

If I do a query looking for the weights of all shipments that had an invoice
raised in a month, where a shipment has had 2 or 3 invoices raised of course
I get the weight 2 or 3 times too.

How can I exclude repeating values, or somehow ensure that I pull the weight
for a particular jobref only once?

Many thanks
CW
 
T

Tim Johnson

Hi CW,

If I'm understanding you correctly, what you might try to do is write a
query using ONLY the Shipment jobref and the weight. Use the "Totals" button
for grouping.

If you need to expand and acquire more information, be sure that there are
NO UNIQUE items EXCEPT where you would like a new row created.

Hope that helps,
Tim
 
C

CW

Tim -
I could do that no problem but unfortunately it is a little more
complicated than that. I need to report "by month" and the date is held in
the second table, sometimes several times for the same job - that's the bit
that's causing my furrowed brow...
Any thoughts on that?
Many thanks
CW
 
K

Ken Sheridan

If you are only including data from the Shipments table in the query's result
table you can use the SELECT DISTINCT option, e.g.

SELECT DISTINCT jobref, weight
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

The above would prompt for the year and month when the query, or any form or
report based on it, is opened.

If you also want to include data from Invoices, however, you can't show the
jobref and weight per jobref only once in the query's result table per se,
but you can do it in a report based on the query. A query in this case might
be something like this:

SELECT jobref, weight, [billing date], [billed amount]
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

Base a report on this query and group it first on on jobref, then on billing
date giving the jobref group a Group Header. Put the controls bound to
jobref and weight in the group header, and those bound to billing date and
billed amount (or whatever) in the detail section. The report will show the
jobref and weight just once, with multiple lines for billing date and billed
amount per job ref.

If in the report you want the job ref and weight on the same line as the
first billing date and billed amount for the jobref then position the job ref
and weight controls to the left of the header section, and the billing date
and billed amount further to the right in the detailed section so there is no
overlap. In the group header's Format event procedure enter:

MoveLayout = False

If you want to aggregate data, e.g. sum the weights in the report footer
then with a report based on the first query you'd just put a text box,
txtTotalWeight say, in the report footer, with a ControlSource property of:

=Sum([weight])

You can't do this with a report based on the second query, however, as it
would sum the (unseen) multiple weight values, not just the seen values.
There are various ways around this. One is to leave the ControlSource of the
txtTotalWeight text box blank and populate it in code like so:

In the report header's Print event procedure put:

' initialize txtTotalWeight control to zero
txtTotalWeight = 0

In the Print event procedure of the group header put:

' increment txtTotalWeight, examining
' the PrintCount property to avoid any
' inadvertent double counting
If PrintCount = 1 Then
txtTotalWeight = txtTotalWeight + weight
End If

One thing to be aware of when using the Print event procedure, however, is
that if in print preview you skip over pages with the navigation buttons the
Print events for the skipped pages won't fire, so the sum will be wrong.
Paging down through all pages in print preview or sending the complete report
to a printer will be fine, though.

Ken Sheridan
Stafford, England
 
T

Tim Johnson

If Ken's answer doesn't work for your needs, you may also want to look into a
Crosstab query.

Ken Sheridan said:
If you are only including data from the Shipments table in the query's result
table you can use the SELECT DISTINCT option, e.g.

SELECT DISTINCT jobref, weight
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

The above would prompt for the year and month when the query, or any form or
report based on it, is opened.

If you also want to include data from Invoices, however, you can't show the
jobref and weight per jobref only once in the query's result table per se,
but you can do it in a report based on the query. A query in this case might
be something like this:

SELECT jobref, weight, [billing date], [billed amount]
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

Base a report on this query and group it first on on jobref, then on billing
date giving the jobref group a Group Header. Put the controls bound to
jobref and weight in the group header, and those bound to billing date and
billed amount (or whatever) in the detail section. The report will show the
jobref and weight just once, with multiple lines for billing date and billed
amount per job ref.

If in the report you want the job ref and weight on the same line as the
first billing date and billed amount for the jobref then position the job ref
and weight controls to the left of the header section, and the billing date
and billed amount further to the right in the detailed section so there is no
overlap. In the group header's Format event procedure enter:

MoveLayout = False

If you want to aggregate data, e.g. sum the weights in the report footer
then with a report based on the first query you'd just put a text box,
txtTotalWeight say, in the report footer, with a ControlSource property of:

=Sum([weight])

You can't do this with a report based on the second query, however, as it
would sum the (unseen) multiple weight values, not just the seen values.
There are various ways around this. One is to leave the ControlSource of the
txtTotalWeight text box blank and populate it in code like so:

In the report header's Print event procedure put:

' initialize txtTotalWeight control to zero
txtTotalWeight = 0

In the Print event procedure of the group header put:

' increment txtTotalWeight, examining
' the PrintCount property to avoid any
' inadvertent double counting
If PrintCount = 1 Then
txtTotalWeight = txtTotalWeight + weight
End If

One thing to be aware of when using the Print event procedure, however, is
that if in print preview you skip over pages with the navigation buttons the
Print events for the skipped pages won't fire, so the sum will be wrong.
Paging down through all pages in print preview or sending the complete report
to a printer will be fine, though.

Ken Sheridan
Stafford, England

CW said:
I need to analyse and report on our shipments by weight on a monthly basis,
in the month within which they are billed. Trouble is, we often raise more
than one bill per shipment, but I only want to report the weight of each
shipment once.

The weight is held in a Shipments table along with the unique jobref (and
other data).
The billing date is held in the Invoices table along with the jobref and
other data.
There's a one-to-many relationship from Shipments.jobref to Invoices.jobref.

If I do a query looking for the weights of all shipments that had an invoice
raised in a month, where a shipment has had 2 or 3 invoices raised of course
I get the weight 2 or 3 times too.

How can I exclude repeating values, or somehow ensure that I pull the weight
for a particular jobref only once?

Many thanks
CW
 
C

CW

Ken -
Thank you so so much for that detailed reply - wonderful - I will give it a
whirl right now and hopefully it'll all be working by the time I get to the
office tomorrow. After all, I've got all night, haven't I !!!
Many thanks again
CW

Ken Sheridan said:
If you are only including data from the Shipments table in the query's result
table you can use the SELECT DISTINCT option, e.g.

SELECT DISTINCT jobref, weight
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

The above would prompt for the year and month when the query, or any form or
report based on it, is opened.

If you also want to include data from Invoices, however, you can't show the
jobref and weight per jobref only once in the query's result table per se,
but you can do it in a report based on the query. A query in this case might
be something like this:

SELECT jobref, weight, [billing date], [billed amount]
FROM Shipments INNER JOIN INVOICES
ON Shipments.jobref = Invoices.jobref
WHERE YEAR([billing date]) = [Enter year:]
AND MONTH([billing date]) = [Enter month as a number:];

Base a report on this query and group it first on on jobref, then on billing
date giving the jobref group a Group Header. Put the controls bound to
jobref and weight in the group header, and those bound to billing date and
billed amount (or whatever) in the detail section. The report will show the
jobref and weight just once, with multiple lines for billing date and billed
amount per job ref.

If in the report you want the job ref and weight on the same line as the
first billing date and billed amount for the jobref then position the job ref
and weight controls to the left of the header section, and the billing date
and billed amount further to the right in the detailed section so there is no
overlap. In the group header's Format event procedure enter:

MoveLayout = False

If you want to aggregate data, e.g. sum the weights in the report footer
then with a report based on the first query you'd just put a text box,
txtTotalWeight say, in the report footer, with a ControlSource property of:

=Sum([weight])

You can't do this with a report based on the second query, however, as it
would sum the (unseen) multiple weight values, not just the seen values.
There are various ways around this. One is to leave the ControlSource of the
txtTotalWeight text box blank and populate it in code like so:

In the report header's Print event procedure put:

' initialize txtTotalWeight control to zero
txtTotalWeight = 0

In the Print event procedure of the group header put:

' increment txtTotalWeight, examining
' the PrintCount property to avoid any
' inadvertent double counting
If PrintCount = 1 Then
txtTotalWeight = txtTotalWeight + weight
End If

One thing to be aware of when using the Print event procedure, however, is
that if in print preview you skip over pages with the navigation buttons the
Print events for the skipped pages won't fire, so the sum will be wrong.
Paging down through all pages in print preview or sending the complete report
to a printer will be fine, though.

Ken Sheridan
Stafford, England

CW said:
I need to analyse and report on our shipments by weight on a monthly basis,
in the month within which they are billed. Trouble is, we often raise more
than one bill per shipment, but I only want to report the weight of each
shipment once.

The weight is held in a Shipments table along with the unique jobref (and
other data).
The billing date is held in the Invoices table along with the jobref and
other data.
There's a one-to-many relationship from Shipments.jobref to Invoices.jobref.

If I do a query looking for the weights of all shipments that had an invoice
raised in a month, where a shipment has had 2 or 3 invoices raised of course
I get the weight 2 or 3 times too.

How can I exclude repeating values, or somehow ensure that I pull the weight
for a particular jobref only once?

Many thanks
CW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top