S
Susan L
Is it possible to calculate totals in a crosstab? I have a crosstab set up
that is based on a union query that separates values that are in columns in
the original table (Valid, Invalid), but that I need to report in rows. (The
xtab reports data by month.)I was going to do the calculations in the report,
but have run into difficulty, because the results of the union query put the
values for the former columns into a single field.
The report for must be set up as follows:
Transactions Jan Feb Mar etc to Dec Total %ofTotal
Valid 170,000 150,000 190,000 nnnn
pp.p%
Invalid 100,000 125,000 160,000 nnnn
pp.p%
Totals 270,000 275,000 350,000 nnnn pp.p%
% Valid 62.9 54.5 54.2 etc to Dec
I can get the totals OK becase the report control Sums the field, but am
unable to calculate the percentage, because I don't know of a way to refer to
the "Valid" part of the transactions field. Not knowing how to do that, I was
thinking maybe I could add two rows to the xtab query to do both the Totals
and % Valid. Is there a way? Otherwise, i guess I'll have to export to Excel,
which I'd prefer not to do.
Here's the xtab SQL:
TRANSFORM Sum(qry_ValInvlTrans_Count2_Union.[Month Total]) AS [SumOfMonth
Total]
SELECT qry_ValInvlTrans_Count2_Union.Transactions,
qry_ValInvlTrans_Count2_Union.Sequence,
Sum(qry_ValInvlTrans_Count2_Union.[Month Total]) AS [Total Of Month Total]
FROM qry_ValInvlTrans_Count2_Union
GROUP BY qry_ValInvlTrans_Count2_Union.Transactions,
qry_ValInvlTrans_Count2_Union.Sequence
ORDER BY qry_ValInvlTrans_Count2_Union.Sequence
PIVOT qry_ValInvlTrans_Count2_Union.Mth In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
And here's the union:
SELECT Format([STDT], "MMM") As Mth, "Valid" as [Transactions], "1" as
Sequence, [VLD_TXN_CNT] as
[Month Total]
FROM tbl_Trans_Val_Inval
UNION ALL SELECT Format([STDT], "MMM") As Mth, "Invalid" as [Transactions],
"2" as Sequence,
[IVLD_TXN_CNT] as [Month Total]
FROM tbl_Trans_Val_Inval;
If someone could let me know whether what I'm asking is possible (or not
possible), I'd be appreciative.
that is based on a union query that separates values that are in columns in
the original table (Valid, Invalid), but that I need to report in rows. (The
xtab reports data by month.)I was going to do the calculations in the report,
but have run into difficulty, because the results of the union query put the
values for the former columns into a single field.
The report for must be set up as follows:
Transactions Jan Feb Mar etc to Dec Total %ofTotal
Valid 170,000 150,000 190,000 nnnn
pp.p%
Invalid 100,000 125,000 160,000 nnnn
pp.p%
Totals 270,000 275,000 350,000 nnnn pp.p%
% Valid 62.9 54.5 54.2 etc to Dec
I can get the totals OK becase the report control Sums the field, but am
unable to calculate the percentage, because I don't know of a way to refer to
the "Valid" part of the transactions field. Not knowing how to do that, I was
thinking maybe I could add two rows to the xtab query to do both the Totals
and % Valid. Is there a way? Otherwise, i guess I'll have to export to Excel,
which I'd prefer not to do.
Here's the xtab SQL:
TRANSFORM Sum(qry_ValInvlTrans_Count2_Union.[Month Total]) AS [SumOfMonth
Total]
SELECT qry_ValInvlTrans_Count2_Union.Transactions,
qry_ValInvlTrans_Count2_Union.Sequence,
Sum(qry_ValInvlTrans_Count2_Union.[Month Total]) AS [Total Of Month Total]
FROM qry_ValInvlTrans_Count2_Union
GROUP BY qry_ValInvlTrans_Count2_Union.Transactions,
qry_ValInvlTrans_Count2_Union.Sequence
ORDER BY qry_ValInvlTrans_Count2_Union.Sequence
PIVOT qry_ValInvlTrans_Count2_Union.Mth In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
And here's the union:
SELECT Format([STDT], "MMM") As Mth, "Valid" as [Transactions], "1" as
Sequence, [VLD_TXN_CNT] as
[Month Total]
FROM tbl_Trans_Val_Inval
UNION ALL SELECT Format([STDT], "MMM") As Mth, "Invalid" as [Transactions],
"2" as Sequence,
[IVLD_TXN_CNT] as [Month Total]
FROM tbl_Trans_Val_Inval;
If someone could let me know whether what I'm asking is possible (or not
possible), I'd be appreciative.