R
ryguy7272
I am trying to do a simple subtraction between two tables. My SQL is below:
SELECT [Wanda - Current Week].Advertiser AS [Current Week Advertiser],
[Wanda - Current Week].SalesRegion AS [Current Week Sales Region], Sum([Wanda
- Current Week].Q409) AS [Current Week Quarter], "13" AS [Current Week],
[Wanda - Prior Week].Advertiser AS [Prior Week Advertiser], [Wanda - Prior
Week].SalesRegion AS [Prior Week Sales Region], Sum([Wanda - Prior
Week].Q409) AS [Prior Week Quarter], "12" AS [Prior Week], Sum(nz([Wanda -
Current Week]![Q409],0)-nz([Wanda - Prior Week]![Q409],0)) AS [Weekly Change]
FROM [Wanda - Current Week] INNER JOIN [Wanda - Prior Week] ON [Wanda -
Current Week].Advertiser = [Wanda - Prior Week].Advertiser
GROUP BY [Wanda - Current Week].Advertiser, [Wanda - Current
Week].SalesRegion, "13", [Wanda - Prior Week].Advertiser, [Wanda - Prior
Week].SalesRegion, "12";
The problem occurs when I subtract the ‘Prior Week Quarter’ from the
‘Current Week Quarter’ and the Sales Region is not exactly the same; then I
get a number greater than zero or less than zero. The data is actually the
same; I had one table named week 13 and one table named week 12! When all
the records in the ‘Current Week Sales Region’ do not match up, I’m getting a
number (positive or negative) for the ‘Weekly Change’ calculation. There
should be zero, but I think some calculations are non-zero because I am using
‘Group By’. Let’s say I am looking at sales to ‘Nestle’ and last week the
sales were done in the ‘East’ and this week sales are done in the ‘West’. Is
there a simple way to overcome this issue? I know everything is from Nestle,
but the ‘East’ and ‘West’ Regions are screwing me up. I haven’t dealt with
it before, and offhand I can’t think of how to handle this in the QBE grid.
Thanks,
Ryan---
SELECT [Wanda - Current Week].Advertiser AS [Current Week Advertiser],
[Wanda - Current Week].SalesRegion AS [Current Week Sales Region], Sum([Wanda
- Current Week].Q409) AS [Current Week Quarter], "13" AS [Current Week],
[Wanda - Prior Week].Advertiser AS [Prior Week Advertiser], [Wanda - Prior
Week].SalesRegion AS [Prior Week Sales Region], Sum([Wanda - Prior
Week].Q409) AS [Prior Week Quarter], "12" AS [Prior Week], Sum(nz([Wanda -
Current Week]![Q409],0)-nz([Wanda - Prior Week]![Q409],0)) AS [Weekly Change]
FROM [Wanda - Current Week] INNER JOIN [Wanda - Prior Week] ON [Wanda -
Current Week].Advertiser = [Wanda - Prior Week].Advertiser
GROUP BY [Wanda - Current Week].Advertiser, [Wanda - Current
Week].SalesRegion, "13", [Wanda - Prior Week].Advertiser, [Wanda - Prior
Week].SalesRegion, "12";
The problem occurs when I subtract the ‘Prior Week Quarter’ from the
‘Current Week Quarter’ and the Sales Region is not exactly the same; then I
get a number greater than zero or less than zero. The data is actually the
same; I had one table named week 13 and one table named week 12! When all
the records in the ‘Current Week Sales Region’ do not match up, I’m getting a
number (positive or negative) for the ‘Weekly Change’ calculation. There
should be zero, but I think some calculations are non-zero because I am using
‘Group By’. Let’s say I am looking at sales to ‘Nestle’ and last week the
sales were done in the ‘East’ and this week sales are done in the ‘West’. Is
there a simple way to overcome this issue? I know everything is from Nestle,
but the ‘East’ and ‘West’ Regions are screwing me up. I haven’t dealt with
it before, and offhand I can’t think of how to handle this in the QBE grid.
Thanks,
Ryan---