Sei sulla pagina 1di 4

I now imagine blog readers who have been working with the tools for a while have started

nodding their heads in agreement, only to stop and say, Hey, wait a second, is Dave talking about universe contexts or report calculation contexts? And the answer is, of course, yes. Both concepts can be quite complicated and take a while to fully understand. Since I have already written a number of blog posts about universe contexts I thought it was time to turn my attention to the report technique of calculation contexts. Note that this concept is used in Desktop Intelligence and Web Intelligence but not in Crystal. This post is intended to be an overview only. I have plans for a detailed post on each of the various context operators where I will go into much more depth. For this post my goal is to introduce the concept and provide some basic definitions.

Introducing Calculation Context


The default calculation context is defined by the dimensions that participate in a report block. It is this feature that makes the dynamic nature of measures possible. When dimensions are removed from or added to a block the context changes and the measure amounts also change. This is controlled by the projection function set on each measure by the universe designer. However, a report writer sometimes wants a measure to be fixed at a particular value. Percentages are a really simple example. To calculate a contribution percentage I need to divide each individual value by the overall grand total. In order to do that, I need to know how to generate the grand total anywhere I want it. In order to do that, I need to understand how to use the various calculation context operators.

Context Operators
There is a simple (but powerful) set of context operators that I can choose from. I intend to briefly define each one in this blog post and then dive into more detail in future posts. As I mentioned when I started, the default context for a measure is based on the dimension values present in the block structure. I can alter which of those dimensions impact the calculation using one of the following three context operators.

In is used to specify exactly which dimensions to include in a context. Other dimensions in the block are ignored. Adding / removing elements from the block does not impact this calculation unless a removed dimension was specified in the context. In that case a #MULTIVALUE error is displayed. ForEach is used to include a dimension in a context. The calculation context is still affected by other values in the block. ForAll is used to exclude a dimension from a context. Other dimensions of the block will still be considered. Adding or removing values from a block might change the value, but it will always ignore the ForAll items.

The operators listed above all require one or more dimensions as part of their syntax. However, calculation context can be specified by more than a set of dimension values. There are a series of report structure keywords that can be used as well.

In Report sets the context at the report or grand total level. Any formula with these keywords for the context will return an overall total. Note that the total may still be affected by report filters. In Block sets the context for each block section. For years I have been waiting for this setting to be renamed to reflect how it really works, but it hasnt. I suppose its for backwards compatibility. If there is only one block on a report then In Block and In Report are going to be the same. But when a block is broken up into sections, then this context will generate a total for each section value. For that reason I submit that a better name might have been In Section instead, but as long as I know what it does the specific word does not really matter. In Body is the standard default context for each row of data.

With Desktop Intelligence we have the option of In CurrentPage which can be quite useful and unfortunately not yet available in Web Intelligence. I probably dont have to explain how the CurrentPage total is derived. Finally, these keywords can appear in several places in a formula. The most common are the input and output context settings, but certain functions (like RunningSum() for example) also have a reset context.

Input context is used to determine the input values for the formula. Output context is used to determine the output scope of the formula. Reset context is used to determine when a running function starts over at zero.

Dimensions referenced in the input context do not have to appear in the block. Output and reset dimensions must appear in the block in order to function correctly. For many calculations the default input context works just fine. I will show an example where its crucial to understand input context later on. For now I would like to move on to a simple example.

Simple Calculation Context Example


Its hard to fully grasp some of the subtleties of calculation context without good examples. For this post I will provide one simple but common example that I mentioned earlier: contribution percent. I will start with a simple block with one dimension (resort), one measure (revenue), and a grand total as shown here.

This block already has a total on it. If this were a typical spreadsheet I could reference the total value using a row/column address, but that doesnt work in Web Intelligence. That means I have to use another technique to generate the grand total. I mentioned the solution earlier all I have to do is create a simple formula that looks like this:

Heres the formula again:


=[Revenue] / [Revenue] In Report

Remember that the In Report context projects the measure up to the overall report total. By using that calculation context operator in the denominator of my division I ensure that I will always be dividing by the grand total in this formula. The results?

Whats Next?
This post barely scratched the surface of the calculation context question. It provided a few brief definitions and one simple example. I have several other posts planned that will dive into much greater detail about this often confusing subject. First I plan to talk more about In versus ForEach versus ForAll and how they are different. Next I plan to cover input versus output context and when each should be used. As I write this post neither of those two are much more than an outline for now, so I dont have an estimated publish date. But theyll get published. Eventually.

Potrebbero piacerti anche