Multidimensional Expressions (MDX) Reference
SQL Server 2012 Books Online
Summary: Multidimensional Expressions (MDX) is the query language that you use to work with and retrieve multidimensional data in Microsoft Analysis Services. MDX is based on the XML for Analysis (XMLA) specification, with specific extensions for SQL Server Analysis Services. MDX utilizes expressions composed of identifiers, values, statements, functions, and operators that Analysis Services can evaluate to retrieve an object (for example a set or a member), or a scalar value (for example, a string or a number).
Category: Reference Applies to: SQL Server 2012
Source: SQL Server Books Online (link to source content)
E-book publication date: June 2012
Copyright © 2012 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.
The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Contents
Multidimensional Expressions (MDX) Reference................................................................................. 8 MDX Syntax Elements.................................................................................................................................... 8 Identifiers......................................................................................................................................................10 Using Regular Identifiers.....................................................................................................................10 Using Delimited Identifiers.................................................................................................................11 Expressions...................................................................................................................................................12 Using Cube and Subcube Expressions...........................................................................................14 Using Dimension Expressions...........................................................................................................16 Using Member Expressions................................................................................................................17 Using Tuple Expressions......................................................................................................................18 Using Set Expressions...........................................................................................................................19 Using Scalar Expressions.....................................................................................................................20 Working with Empty Values...............................................................................................................22 Operators (MDX Syntax).........................................................................................................................25 Arithmetic Operators............................................................................................................................28 Bitwise Operators...................................................................................................................................29 Comparison Operators........................................................................................................................29 Concatenation Operators...................................................................................................................31 Set Operators..........................................................................................................................................31 Unary Operators.....................................................................................................................................32 Assignment Operators.........................................................................................................................33 Functions (MDX Syntax)..........................................................................................................................33 Using String Functions.........................................................................................................................35 Using Mathematical Functions.........................................................................................................37 Using Logical Functions.......................................................................................................................37 Using Member Functions....................................................................................................................38 Using Tuple Functions..........................................................................................................................39 Using Set Functions ..............................................................................................................................39 Using Dimension, Hierarchy, and Level Functions ....................................................................43 Using Stored Procedures....................................................................................................................44 Comments (MDX Syntax)........................................................................................................................44 Reserved Keywords (MDX Syntax) ......................................................................................................46
MDX Language Reference..........................................................................................................................46 MDX Syntax Conventions.......................................................................................................................47 MDX Statement Reference.....................................................................................................................48 MDX Scripting Statements.................................................................................................................48 MDX Data Definition Statements.....................................................................................................54 MDX Data Manipulation Statements..............................................................................................94 MDX Operator Reference.................................................................................................................... 113
-- (Comment)........................................................................................................................................ 115 - (Except)................................................................................................................................................ 117 - (Negative)........................................................................................................................................... 118 - (Subtract)............................................................................................................................................. 119 * (Crossjoin)........................................................................................................................................... 120 * (Multiply)............................................................................................................................................. 121 / (Divide)................................................................................................................................................. 122 ^ (Power)................................................................................................................................................ 124 /*...*/ (Comment)................................................................................................................................. 125 // (Comment)........................................................................................................................................ 126 : (Range) ................................................................................................................................................. 127 + (Add).................................................................................................................................................... 128 + (Positive)............................................................................................................................................. 129 + (String Concatenation) ................................................................................................................. 130 + (Union)................................................................................................................................................ 130 < (Less Than) ........................................................................................................................................ 132 <= (Less Than or Equal To)............................................................................................................. 133 <> (Not Equal To)............................................................................................................................... 134 = (Equal To)........................................................................................................................................... 135 > (Greater Than).................................................................................................................................. 136 >= (Greater Than or Equal To)....................................................................................................... 137 AND.......................................................................................................................................................... 138 IS140 NOT.......................................................................................................................................................... 141 OR............................................................................................................................................................. 142 XOR .......................................................................................................................................................... 144 MDX Function Reference..................................................................................................................... 145 AddCalculatedMembers................................................................................................................... 157 Aggregate.............................................................................................................................................. 158 AllMembers........................................................................................................................................... 162 Ancestor ................................................................................................................................................. 164 Ancestors ............................................................................................................................................... 166 Ascendants............................................................................................................................................ 168 Avg ........................................................................................................................................................... 169 Axis........................................................................................................................................................... 172 BottomCount........................................................................................................................................ 174 BottomPercent..................................................................................................................................... 175 BottomSum........................................................................................................................................... 176 CalculationCurrentPass..................................................................................................................... 177 CalculationPassValue......................................................................................................................... 178 CASE Statement................................................................................................................................... 179 Children .................................................................................................................................................. 182 ClosingPeriod....................................................................................................................................... 183 CoalesceEmpty..................................................................................................................................... 185 Correlation............................................................................................................................................. 187 Count (Dimension)............................................................................................................................. 188 Count (Hierarchy Levels).................................................................................................................. 188 Count (Set)............................................................................................................................................. 189 Count (Tuple)........................................................................................................................................ 192 Cousin ..................................................................................................................................................... 192 Covariance............................................................................................................................................. 194 CovarianceN.......................................................................................................................................... 195 Crossjoin................................................................................................................................................. 196 Current.................................................................................................................................................... 198 CurrentMember................................................................................................................................... 199 CurrentOrdinal..................................................................................................................................... 202 CustomData.......................................................................................................................................... 203 DataMember......................................................................................................................................... 204 DefaultMember ................................................................................................................................... 205 Descendants ......................................................................................................................................... 206 Dimension.............................................................................................................................................. 211 Dimensions............................................................................................................................................ 212 Distinct.................................................................................................................................................... 214 DistinctCount........................................................................................................................................ 215 DrilldownLevel...................................................................................................................................... 216 DrilldownLevelBottom....................................................................................................................... 218 DrilldownLevelTop.............................................................................................................................. 220 DrilldownMember............................................................................................................................... 221 DrilldownMemberBottom................................................................................................................ 223 DrilldownMemberTop....................................................................................................................... 225 DrillupLevel............................................................................................................................................ 226 DrillupMember..................................................................................................................................... 227 Error ......................................................................................................................................................... 230 Except...................................................................................................................................................... 230 Exists........................................................................................................................................................ 231 Extract...................................................................................................................................................... 233 Filter......................................................................................................................................................... 235 FirstChild ................................................................................................................................................ 236 FirstSibling............................................................................................................................................. 237 Generate................................................................................................................................................. 238 Head......................................................................................................................................................... 240 Hierarchize............................................................................................................................................. 242 Hierarchy................................................................................................................................................ 244 IIf244 Instr.......................................................................................................................................................... 247 Intersect.................................................................................................................................................. 250 IsAncestor.............................................................................................................................................. 252 IsEmpty................................................................................................................................................... 253 IsGeneration.......................................................................................................................................... 254 IsLeaf........................................................................................................................................................ 255 IsSibling .................................................................................................................................................. 255 Item (Member)..................................................................................................................................... 256 Item (Tuple)........................................................................................................................................... 257 KPIGoal.................................................................................................................................................... 259 KPIStatus ................................................................................................................................................ 260 KPITrend................................................................................................................................................. 261 KPIWeight.............................................................................................................................................. 262 KPICurrentTimeMember................................................................................................................... 262 KPIValue.................................................................................................................................................. 263 Lag............................................................................................................................................................ 264 LastChild................................................................................................................................................. 265 LastPeriods............................................................................................................................................ 265 LastSibling.............................................................................................................................................. 267 Lead.......................................................................................................................................................... 267 Leaves...................................................................................................................................................... 268 Level......................................................................................................................................................... 269 Levels....................................................................................................................................................... 270 LinkMember.......................................................................................................................................... 271 LinRegIntercept ................................................................................................................................... 272 LinRegPoint........................................................................................................................................... 273 LinRegR2................................................................................................................................................ 275 LinRegSlope.......................................................................................................................................... 276 LinRegVariance.................................................................................................................................... 277 LookupCube.......................................................................................................................................... 278 Max........................................................................................................................................................... 279 MeasureGroupMeasures.................................................................................................................. 281 Median.................................................................................................................................................... 281 Members (Set)...................................................................................................................................... 283 Members (String)................................................................................................................................ 284 MemberToStr ....................................................................................................................................... 285 MemberValue....................................................................................................................................... 286 Min ........................................................................................................................................................... 287 Mtd........................................................................................................................................................... 288 Name....................................................................................................................................................... 289 NameToSet............................................................................................................................................ 290 NextMember......................................................................................................................................... 291 NonEmpty.............................................................................................................................................. 292 NonEmptyCrossjoin........................................................................................................................... 294 OpeningPeriod..................................................................................................................................... 295 Order........................................................................................................................................................ 296 Ordinal .................................................................................................................................................... 301 ParallelPeriod........................................................................................................................................ 302 Parent...................................................................................................................................................... 303 PeriodsToDate...................................................................................................................................... 304 Predict..................................................................................................................................................... 306 PrevMember......................................................................................................................................... 307 Properties............................................................................................................................................... 309 Qtd............................................................................................................................................................ 311 Rank......................................................................................................................................................... 312 RollupChildren ..................................................................................................................................... 314 Root.......................................................................................................................................................... 316 SetToArray............................................................................................................................................. 317 SetToStr.................................................................................................................................................. 318 Siblings.................................................................................................................................................... 319 Stddev..................................................................................................................................................... 320 StddevP................................................................................................................................................... 320 Stdev........................................................................................................................................................ 320 StdevP ..................................................................................................................................................... 321 StripCalculatedMembers.................................................................................................................. 322 StrToMember ....................................................................................................................................... 324 StrToSet.................................................................................................................................................. 326 StrToTuple ............................................................................................................................................. 327 StrToValue............................................................................................................................................. 329 Subset...................................................................................................................................................... 330 Sum .......................................................................................................................................................... 331 Tail ............................................................................................................................................................ 333 This........................................................................................................................................................... 334 ToggleDrillState................................................................................................................................... 335 TopCount............................................................................................................................................... 337 TopPercent............................................................................................................................................ 338 TopSum .................................................................................................................................................. 341 TupleToStr ............................................................................................................................................. 343 Union....................................................................................................................................................... 344 UniqueName......................................................................................................................................... 346 UnknownMember............................................................................................................................... 347 Unorder................................................................................................................................................... 349 UserName.............................................................................................................................................. 350 ValidMeasure........................................................................................................................................ 350 Value........................................................................................................................................................ 352 Var ............................................................................................................................................................ 353 Variance.................................................................................................................................................. 354 VarianceP ............................................................................................................................................... 354 VarP.......................................................................................................................................................... 354 VisualTotals........................................................................................................................................... 355 Wtd........................................................................................................................................................... 356 Ytd ............................................................................................................................................................ 357 MDX Reserved Words........................................................................................................................... 358