Question for y'all!
I have the following query:
SELECT
"tblLoads"."BillToID",
"tblLoads"."BillToName",
AVG("tblLoads"."TotalRevenue") as REV,
YEAR("tblLoads"."InvoiceDate") as YEAR,
"tblLoads"."InvoiceDate",
"tblLoads"."PickupDate",
"tblLoads"."DeliveryDate",
"tblLoads"."LoadID",
Count("tblLoads"."LoadID") as LdID,
SUM("tblLoadDispatch"."DriverPay") as Charges,
"tblLoads"."LoadClass",
"tblLoads"."OfficeCode",
"tblLoads"."Status",
"tblLoads"."Salesperson"
FROM tblLoads
LEFT OUTER JOIN
tblLoadDispatch
ON (tblLoads.LoadID = tblLoadDispatch.LoadID)
WHERE
tblLoads.LoadID = tblLoadDispatch.LoadID and
tblLoads.Status <> 'CANCELLED' And tblLoads.Status <> 'INACTIVE' AND tblLoads.LoadClass <> 'TLQUOTE' And tblLoads.LoadClass <> 'LTLQUOTE'
GROUP BY
"tblLoads"."BillToID",
"tblLoads"."BillToName",
"tblLoads"."InvoiceDate",
"tblLoads"."PickupDate",
"tblLoads"."DeliveryDate",
"tblLoads"."LoadID",
"tblLoads"."TotalRevenue",
"tblLoads"."LoadClass",
"tblLoads"."OfficeCode",
"tblLoads"."Status",
"tblLoads"."Salesperson"
And I run it with a customized record selection formula for dates:
{Command.InvoiceDate} IN ((YearToDate)) or
{Command.InvoiceDate} IN ((LastYearYTD))
This enables me to do a year-over-year comparison using one query and have data at the BillToName grouping in 2006 and 2007,
My difficulty lies in couting the LoadID values by the year. For example:
BillToName 1 2007 LoadID Cnt 2006 LoadID Cnt
Customer A 27 42
As it sits, the DistinctCount function adds up all the LoadID's regardless of year. I have tried the following:
IF statement with DistinctCount
Custom Field Counting the LoadID for the single record
And a number of others . . .
Any ideas?
Thanks so much!!
SRK