Re: Crosstab design problem -
07-28-2010
, 04:51 AM
Solved the problem, but with a little added complexity (sadly).
There is no way to perform aggregations in any form (it seems) inside
an IIf. This even applies to using sub selects. Attempts to have
calculated (but not shown) columns failed because it seems that even
if you name them in the query designer, you cannot reference them in
another column inside the same query. If there is a way to do this
please let me know!
In the end I created a relatively simple query structure that provided
the 'today' data alongside the 'historical' data in a single query,
along with fields needed later to filter for the different reports. I
think I stated this above in an earlier post. Anyway, to get to the
crosstab bit, it was necessary to pre-aggregate the data. To do this I
created a 'pre' query for each crosstab that did the formula
expressions for me using a normal select type query. I named the
expressions to what I wanted for easier use later in the crosstab.
In the crosstab, I based the data on the pre-query, and included the
unjoined xHeaders table I mentioned in an earlier post, and did the
column header as formula thing as listed before (previous post). Now
all I had to do was get the data into the appropriate cells, and to do
this I used the following:
TheValue: FormatPercent(Max(IIf([FieldName]="Achieved",[Achieved],
[Variance])))
[Achieved] and [Variance] are the expression fields from the pre-
aggregate query. Since there is only one value for each combination,
the summary function you choose to use really could be any of Max,
Min, Sum, Avg, and they can only ever return that one value. In short
the right value goes into the right cell, and it is quick to run.
The only part that I wish I knew how to do, and I am so far unable to
find a way to do it, or for that matter even a reference to it in
Google, is to be able to use the value in a calculated column in a
crosstab that isnt shown (ie/ not a row, column or value). If this is
possible then the pre-aggregation query can be eliminated.
Can anyone shed some light on the use of calculated fields that arent
shown in crosstab queries? Do they serve any purpose at all?
Cheers
The Frog |