Calculate Variance In Crosstab

Z

zyus

With my sql below

TRANSFORM Sum(QunionALLDATA.[NET_BAL]) AS SumOfNET_BAL
SELECT QunionALLDATA.[SUBCATDESC2]
FROM QunionALLDATA
GROUP BY QunionALLDATA.[SUBCATDESC2]
PIVOT QunionALLDATA.[MthTag];

it produced this result

subcatdesc2 current month previous month
A 1000 900
B 2000 3000

is it possible to calculate variance between current month & previous month
and i expect the new result will be as follow :


subcatdesc2 current month previous month var
A 1000 900 100
B 2000 3000 -1000


Thanks
 
D

Duane Hookom

Try:

SELECT [SUBCATDESC2], Sum(Abs(MthTag="Current Month") * Net_Bal) as
CurrentMonth,
Sum(Abs(MthTag="Previous Month") * Net_Bal) as PreviousMonth ,
Sum(Abs(MthTag="Current Month") * Net_Bal)-Sum(Abs(MthTag="Previous Month")
* Net_Bal) As Var
FROM QunionALLDATA
GROUP BY QunionALLDATA.[SUBCATDESC2];
 
Z

zyus

Thanks duane....its worked

Duane Hookom said:
Try:

SELECT [SUBCATDESC2], Sum(Abs(MthTag="Current Month") * Net_Bal) as
CurrentMonth,
Sum(Abs(MthTag="Previous Month") * Net_Bal) as PreviousMonth ,
Sum(Abs(MthTag="Current Month") * Net_Bal)-Sum(Abs(MthTag="Previous Month")
* Net_Bal) As Var
FROM QunionALLDATA
GROUP BY QunionALLDATA.[SUBCATDESC2];

--
Duane Hookom
MS Access MVP


zyus said:
With my sql below

TRANSFORM Sum(QunionALLDATA.[NET_BAL]) AS SumOfNET_BAL
SELECT QunionALLDATA.[SUBCATDESC2]
FROM QunionALLDATA
GROUP BY QunionALLDATA.[SUBCATDESC2]
PIVOT QunionALLDATA.[MthTag];

it produced this result

subcatdesc2 current month previous month
A 1000 900
B 2000 3000

is it possible to calculate variance between current month & previous
month
and i expect the new result will be as follow :


subcatdesc2 current month previous month var
A 1000 900 100
B 2000 3000 -1000


Thanks
 

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