Compare previous year count for same previous sum amount

smithn293

New Member
Joined
Aug 18, 2009
Messages
31
I have data in 2 tables like this:

Table2010
ShipmentID (unique, PK)
ShipMonth
ShipYear
Weight

Table2011
ShipmentID (unique, PK)
ShipMonth
ShipYear
Weight


Each record represents a shipment. I am trying to do the following:

For the same total weight in a given calendar month, I want to compare the number of shipments (number of records) in 2011 that resulted for the same total weight for the previous year's month.

For example:

Table2010
ShipID DateMonth DateYear Weight (lb)
100 01 2010 200
101 01 2010 200
102 01 2010 200

Table2011
ShipID DateMonth DateYear Weight (lb)
100 01 2011 300
101 01 2011 350

The resulting record should look like:

DateMonth PrevYearSummedWeight ShipCount2010 ShipCount 2011
01 600 3 2


I've tried a ton of ways to include a where clause subquery to compare summed amounts, but nothing is working.

Any help is greatly appreciated!

Thanks.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
this might help get you started, but I'm sure you'll have to change some stuff

make a query
Code:
SELECT 
  Table2010.ShipMonth, 
  count(*) AS NumberItems, 
  sum(Table2010.Weight) AS TotalWeight
FROM 
  Table2010
GROUP BY 
  Table2010.ShipMonth;

save as select_from_2010

make another query
Code:
SELECT 
  Table2011.ShipMonth, 
  count(*) AS NumberItems, 
  sum(Table2011.Weight) AS TotalWeight
FROM 
  Table2011
GROUP BY 
  Table2011.ShipMonth;

save as select_from_2011


make another query
Code:
SELECT 
  select_from_2010.ShipMonth, 
  select_from_2010.TotalWeight, 
  select_from_2010.NumberItems, 
  select_from_2011.NumberItems
FROM 
  select_from_2010 
    INNER JOIN 
      select_from_2011 
        ON 
          select_from_2010.ShipMonth = select_from_2011.ShipMonth
WHERE 
(
  (
    select_from_2010.TotalWeight <= [select_from_2011].[TotalWeight]
  )
);

save as compare_2010_2011
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top