1. I don't see why not. Assuming sales (bookings?) and shipments are two separate queries, join them together on year/month
2. yes, but not as you are showing it, use a subquery to sum bookings-shipments where year/month<=current year/month - assumes year/month is yyyymm (not the full month year you have at the moment)
pure guess how you are doing it at the moment but perhaps salesquery (Q1) is
Code:
SELECT format(Saledate,"yyyymm") as yrMth, Year(SaleDate) as Yr, format(SaleDate, "mmmm yyyy") as Mth, Sum(SaleQuant) as SaleQty, Sum(SaleValue) as SaleAmount
FROM tblSales
GROUP BY format(Saledate,"yyyymm"), Year(SaleDate) , format(SaleDate, "mmmm yyyy")
similar for the shipquery (Q2)
Code:
SELECT format(Shipdate,"yyyymm") as yrMth, Year(ShipDate) as Yr, format(ShipDate, "mmmm yyyy") as Mth, Sum(ShipQuant) as ShipQty, Sum(ShipValue) as ShipAmount
FROM tblShipping
GROUP BY format(Shipdate,"yyyymm"), Year(ShipDate) , format(ShipDate, "mmmm yyyy")
for 1 above (Q3)
Code:
SELECT Q1.yrmth, Q1.yr, Q1.mth, Q1.SaleQty, Q1.SaleAmt, Q2.ShipQty, Q2.ShipAmt
FROM Q1 INNER JOIN Q2 ON Q1.yrmth=Q2.yrmth
for 2 above to include the backlog base another query on Q3
Code:
SELECT A.yrmth, A.yr, A.mth, A.SaleQty, A.SaleAmt, A.ShipQty, A.ShipAmt, sum(B.SaleQty-B.ShipQty) as QtyBacklog, sum(B.SaleAmt-B.ShipAmt) as AmtBacklog
FROM Q3 A INNER JOIN Q3 B ON A.yrmth>=B.yrmth
note the modified join, create as normal in the query builder, then go into the sql window and change it.
alternative you can do in the query window is a cartesian query (no join), but will be slower for large datasets
Code:
SELECT A.yrmth, A.yr, A.mth, A.SaleQty, A.SaleAmt, A.ShipQty, A.ShipAmt, sum(B.SaleQty-B.ShipQty) as QtyBacklog, sum(B.SaleAmt-B.ShipAmt) as AmtBacklog
FROM Q3 A, Q3 B
WHERE A.yrmth>=B.yrmth