Chapter 55. Managing context in MDX
When writing MDX queries, you usually start with a goal you need to achieve. Whether this goal is to return a simple data set or to perform calculations, you need to be aware of context. Context affects all sections of your queries and is an important background setting. Understanding and managing it correctly greatly simplifies and demystifies the query logic and outcomes.
To begin our exploration of context, we will start with its broader side, distinguishing and describing the three overarching context types: cube, session, and query context.
- Cube context— When you define calculations and named sets in the cube script, they can be used and shared by all sessions and queries against that cube. But as you’ll see later in this chapter, they aren’t affected by some MDX query statements.
- Session context— You can also define calculations and named sets in your MDX query sessions. If you do that, all queries in the same session can share the same calculations for the duration of the session. Session context overrides cube context.
- Query context— The smallest grain of context you can use is the query context. Calculations in the query context exist only for the duration of the query and are visible only within the query. Query context overrides both session and cube contexts.