400 Practical PowerPivot & DAX Formulas for Excel 2010
M
ultiDimensional eXpressions (MDX) is a very powerful query language for
extracting data from cubes. While PowerPivot can generate sophisticated
MDX for you, you may want the total control that writing your own MDX
gives you. You can use MDX to import from either an SSAS cube or a PowerPivot
model that has been published to PowerPivot for SharePoint. This appendix demonstrates
some of the fundamentals of MDX. It also shows how best to adapt your MDX for
PowerPivot.
C
Key concepts Cube dimensions and measures, Crossjoin() function,
navigating hierarchies, ranges, sorting, filtering, calculated measures, key
performance indicators (KPIs), natural user hierarchies, attribute hierarchies
Why Write MDX Queries?
MDX is a standard language for extracting data from a multidimensional database.
Specifically, it is the language used to query cubes in an SSAS database or to extract
data from a PowerPivot model that has been published to PowerPivot for SharePoint.
Both are supported from PowerPivot for Excel. Hyperion Essbase and SAP BW cubes
also use MDX, but these are not directly supported by PowerPivot.
Writing your own MDX gives you more power and flexibility. There is a graphical
query designer for MDX in PowerPivot—it’s very good, but sometimes you need just
that little extra control. In addition, you can avail yourself of the extra power of the
SSMS MDX query editor. There is one small proviso—sometimes, the MDX you write
in SSMS is better expressed in a slightly different way for PowerPivot. This appendix
contains a couple of examples that show this.
If you are interested in learning a bit more about MDX (in particular, MDX for
SQL Server Analysis Services), you are referred to my book Practical MDX Queries for
Microsoft SQL Server Analysis Services 2008 (McGraw-Hill/Professional, 2010). Most
of the examples in this appendix are adapted from that book—the rewritten examples
(rewritten to provide better data specifically for PowerPivot) are new. All of the
examples are against an SSAS cube, not a PowerPivot model published to SharePoint,
although the principles are the same.
Where to Create and Test MDX Queries
MDX is a standard language for querying cubes. The MDX discussed here is for
SSAS. The MDX used by other vendors of multidimensional databases may differ in
minor ways. In PowerPivot, you can only use MDX directly against SSAS cubes or
PowerPivot models on SharePoint.
It’s probably a good idea to write and test your MDX queries in SSMS. If they don’t
work there, they are not going to work in PowerPivot.