Skip to main content

MDX Functions

MDX (Multidimensional Expressions) is a language for multidimensional data analysis, primarily used in OLAP (On-Line Analytical Processing) systems for multidimensional data querying, analysis, statistics, and reporting. Datafor utilizes MDX functions and MDX query statements to access, aggregate, filter, and compute multidimensional data. The calculated metrics in Datafor are defined and computed through MDX functions and MDX query statements.

MDX functions are a crucial element of the MDX language, used to handle multidimensional data, including accessing, aggregating, filtering, and computing multidimensional data. MDX functions can be categorized as follows:

  1. Aggregate functions: Used to summarize data, typically for statistics like the total, average, maximum, and minimum of a specific field in a dataset. Examples include COUNT, SUM, MIN, MAX, and AVG.
  2. Set functions: Used to manipulate sets, including union, intersection, and complement operations. These functions are often used in multidimensional data queries and analysis to retrieve specific data. Examples include INTERSECT, UNION, and COMPLEMENT.
  3. Member functions: Used to obtain members and attributes from the dimension hierarchy. These functions are typically used in multidimensional data queries and analysis to retrieve specific data. Examples include MEMBER, DIMENSION, and LEVEL.
  4. Time functions: Used to handle time-related data, including date addition/subtraction, timestamp conversion, and date formatting. These functions are often used in multidimensional data queries and analysis to retrieve specific data. Examples include DATEADD, TIMESTAMP, and FORMAT.
  5. Logical functions: Used for logical judgments and operations, including IF, CASE, AND, OR, and NOT. These functions are typically used in multidimensional data queries and analysis to retrieve specific data.
  6. String functions: Used to handle strings, including string concatenation, string replacement, and string formatting. These functions are often used in multidimensional data queries and analysis to retrieve specific data. Examples include CONCATENATE, REPLACE, and FORMATSTRING.
  7. Mathematical functions: Used to perform mathematical calculations, including absolute value, square root, and exponentiation. These functions are typically used in multidimensional data queries and analysis to retrieve specific data. Examples include ABS, SQRT, and EXP.
  8. Type conversion: Used to convert data types, such as converting strings to numbers, numbers to strings, and dates to strings. These functions are often used in multidimensional data queries and analysis to retrieve specific data. Examples include CSTR, CINT, and CDATE.

Aggregation Functions

Function NameDescriptionSyntaxExample
COUNTCalculates the number of members or elements in a setCOUNT( [Set_Expression] )COUNT( {[Measures].[Sales]} )
SUMCalculates the sum of members or elements in a setSUM( [Set_Expression] )SUM( {[Measures].[Sales]} )
AVGCalculates the average of members or elements in a setAVG( [Set_Expression] )AVG( {[Measures].[Sales]} )
MINCalculates the minimum value of members or elements in a setMIN( [Set_Expression] )MIN( {[Measures].[Sales]} )
MAXCalculates the maximum value of members or elements in a setMAX( [Set_Expression] )MAX( {[Measures].[Sales]} )
DISTINCTCOUNTCalculates the number of distinct members in a setDISTINCTCOUNT( [Set_Expression] )DISTINCTCOUNT( {[Customers].Members} )
AGGREGATEReturns the aggregated value of specified elementsAGGREGATE( [Value] )AGGREGATE( {[Time].[1997].[Q1], [Time].[1997].[Q2]} * {[Measures].[Sales]})

Set Functions

NameDescriptionSyntaxExample
FILTERReturns the members or elements in a set that meet a specified conditionFILTER( [Set_Expression], [Boolean_Expression] )FILTER( {[Customers].Members}, [Measures].[Sales] > 1000 )
NONEMPTYReturns the non-empty members or elements that intersect with other dimensions in the queryNONEMPTY( [Set_Expression] )NONEMPTY( {[Customers].Members} * {[Time].[1997].[Q1]})
ORDERReturns the members or elements in a set that are sorted according to a specified criterionORDER( [Set_Expression], [Numeric_Expression], [Order_Type] )ORDER( {[Customers].Members}, [Measures].[Sales], DESC )
GENERATEReturns a set composed of a group of members selected from a first set and a set of members generated by a generation expressionGENERATE( [Set_Expression], [Generator_Expression] )GENERATE( {[Customers].Members}, {[Products].Members}.CurrentMember.Name )
UNIONReturns the union of two setsUNION( [Set_Expression_1], [Set_Expression_2] )UNION( {[Customers].[USA].[CA], [Customers].[USA].[OR]}, {[Customers].[USA].[WA]]}
INTERSECTReturns the intersection of two setsINTERSECT( [Set_Expression_1], [Set_Expression_2] )INTERSECT( {[Customers].[USA].[CA], [Customers].[USA].[OR]}, {[Customers].[USA].[WA]]}
EXCEPTReturns the set difference of two setsEXCEPT( [Set_Expression_1], [Set_Expression_2] )EXCEPT( {[Customers].[USA].[CA], [Customers].[USA].[OR]}, {[Customers].[USA].[WA]]}
DISTINCTReturns a subset of all distinct members or elements in a setDISTINCT( [Set_Expression] )DISTINCT( {[Customers].Members} )
CROSSJOINReturns the Cartesian product of two or more setsCROSSJOIN( [Set_Expression_1], [Set_Expression_2], ... )CROSSJOIN( {[Customers].[USA].[CA], [Customers].[USA].[OR]}, {[Products].Members} )
TUPLECreates a tuple containing multiple elementsTUPLE( { [Set_Expression_1], [Set_Expression_2], ... } )TUPLE( { [Customers].[USA].[CA], [Time].[1997].[Q1] } )

Member Functions

NameDescriptionSyntaxExample
CURRENTMEMBERReturns the current member in the contextCURRENTMEMBER{[Customers].[USA].[CA]}
PARENTReturns the parent member of a specified memberPARENT( [Member_Expression] )PARENT( {[Customers].[USA].[CA]} )
CHILDRENReturns all children members of a specified memberCHILDREN( [Member_Expression] )CHILDREN( {[Time].[1997].[Q1]})
SIBLINGSReturns all sibling members of a specified memberSIBLINGS( [Member_Expression] )SIBLINGS( {[Customers].[USA].[CA]})
ANCESTORReturns all ancestors of a specified memberANCESTOR( [Member_Expression], [Numeric_Expression] )ANCESTOR( {[Customers].[USA].[CA]}, 2)
DESCENDANTReturns all descendants of a specified memberDESCENDANT( [Member_Expression], [Numeric_Expression] )DESCENDANT( {[Customers].[USA]}, 2)
LEADReturns a specified number of next level membersLEAD( [Member_Expression], [Numeric_Expression] )LEAD( {[Time].[1997].[Q1]}, 2)
LAGReturns a specified number of previous level membersLAG( [Member_Expression], [Numeric_Expression] )LAG( {[Time].[1997].[Q1]}, 2)
FIRSTCHILDReturns the first child member of a specified memberFIRSTCHILD( [Member_Expression] )FIRSTCHILD( {[Time].[1997].[Q1]})
LASTCHILDReturns the last child member of a specified memberLASTCHILD( [Member_Expression] )LASTCHILD( {[Time].[1997].[Q1]})
HIERARCHIZEOrders a set to form a hierarchy using a specified orderHIERARCHIZE( [Set_Expression] )HIERARCHIZE( {[Customers].[USA].[CA], [Customers].[USA].[OR], [Customers].[USA].[WA]})
STRTOSETInterprets a string as an MDX set expressionSTRTOSET( [String_Expression] )STRTOSET( "{[Customers].[USA].[CA], [Customers].[USA].[OR], [Customers].[USA].[WA]}" )
STRTOMEMBERInterprets a string as an MDX member expressionSTRTOMEMBER( [String_Expression] )STRTOMEMBER( "[Customers].[USA].[CA]" )
TAILReturns all descendants of a specified member except for the first childTAIL( [Member_Expression], [Numeric_Expression] )TAIL( {[Customers].[USA]}, 1)
HEADReturns all descendants of a specified member except for the last childHEAD( [Member_Expression], [Numeric_Expression] )HEAD( {[Customers].[USA]}, 1)
ASCENDANTSReturns all ancestors of a specified member in ascending orderASCENDANTS( [Member_Expression] )ASCENDANTS( {[Customers].[USA].[CA]})
DESCENDANTSReturns all descendants of a specified member in descending orderDESCENDANTS( [Member_Expression] )DESCENDANTS( {[Customers].[USA]})
LEVELSReturns all levels in a specified setLEVELS( [Set_Expression] )LEVELS( {[Customers].Members})
MEMBERSReturns all members in a specified dimensionMEMBERS( [Dimension_Expression], [Optional_Set_Expression] )MEMBERS( [Customers] )
DIMENSIONSReturns a set containing all dimensions used in the queryDIMENSIONSDIMENSIONS
HIERARCHYReturns the hierarchy of a specified memberHIERARCHY( [Member_Expression] )HIERARCHY( {[Customers].[USA].[CA]})
MEMBERCAPTIONReturns the caption of a specified memberMEMBERCAPTION( [Member_Expression] )MEMBERCAPTION( {[Customers].[USA].[CA]})
MEMBERNAMEReturns the name of a specified memberMEMBERNAME( [Member_Expression] )MEMBERNAME( {[Customers].[USA].[CA]})
  • Time Functions

    Function NameDescription and SyntaxSyntaxExample
    NOWReturns the current date and timeNOWNOW
    TODAYReturns the current dateTODAYTODAY
    YEARTODATEReturns the time period from the beginning of the year to a specified dateYEARTODATE( [Date_Member] )YEARTODATE( [Time].[1997].[Q1] )
    QUARTERSTODATEReturns the time period from the beginning of the quarter to a specified dateQUARTERSTODATE( [Date_Member] )QUARTERSTODATE( [Time].[1997].[Q1] )
    MONTHSTODATEReturns the time period from the beginning of the month to a specified dateMONTHSTODATE( [Date_Member] )MONTHSTODATE( [Time].[1997].[Q1] )
    WEEKSTODATEReturns the time period from the beginning of the week to a specified dateWEEKSTODATE( [Date_Member] )WEEKSTODATE( [Time].[1997].[W1] )
    DAYSTODATEReturns the time period from the beginning of the day to a specified dateDAYSTODATE( [Date_Member] )DAYSTODATE( [Time].[1997].&[19970401] )
    DATEADDReturns a date a specified number of intervals after a specified dateDATEADD( [Time_Interval], [Date_Member] )DATEADD( "YY", 1, [Time].[1997].[Q1] )
    DATEDIFFReturns the time interval between two datesDATEDIFF( [Time_Interval], [Date_Member_1], [Date_Member_2] )DATEDIFF( "YY", [Time].[1997].[Q1], [Time].[1998].[Q1] )
    PARALLELPERIODReturns a member from the same time period as a specified member in the previous periodPARALLELPERIOD( [Time_Interval], [Numeric_Expression], [Member_Expression] )PARALLELPERIOD( "Q", 2, [Time].[1997].[Q1] )
    OPENINGPERIODReturns the time period from a specified date to the first member of the time periodOPENINGPERIOD( [Time_Interval], [Date_Member] )OPENINGPERIOD( "Q", [Time].[1997].[Q2].[4] )
    CLOSINGPERIODReturns the time period from a specified date to the last member of the time periodCLOSINGPERIOD( [Time_Interval], [Date_Member] )CLOSINGPERIOD( "Q", [Time].[1997].[Q2].[4] )
    PERIODSTODATEReturns the time period from the beginning of the time period to a specified datePERIODSTODATE( [Time_Interval], [Date_Member] )PERIODSTODATE( "Q", [Time].[1997].[Q1] )
    DATESBETWEENReturns all dates between two datesDATESBETWEEN( [Date_Member_1], [Date_Member_2] )DATESBETWEEN( [Time].[1997].[Q1], [Time].[1998].[Q1] )

    Note: The TIMEINTERVAL parameter is a string and can take the following values:

    • YY, YYYY: Year
    • Q: Quarter
    • M, MM: Month
    • D, DD: Day
    • W, WW: Week
    • H, HH: Hour
    • N, NN: Minute
    • S,

Logical Functions

Function NameDescription and ExplanationSyntaxExample
IIFReturns one of two possible values based on a conditionIIF( [Boolean_Expression], [Value_If_True], [Value_If_False] )IIF( [Measures].[Sales] > 5000, "High", "Low" )
SWITCHReturns different values based on multiple conditionsSWITCH( [Numeric_Expression_1], [Value_1], [Numeric_Expression_2], [Value_2], ... )SWITCH( [Measures].[Sales], 100, "Not 100", 200, "Not 200", "Unknown" )
ANDReturns TRUE if all conditions are TRUEAND( [Boolean_Expression_1], [Boolean_Expression_2], ... )AND( [Measures].[Sales] > 5000, [Time].[1997].[Q1] )
ORReturns TRUE if any condition is TRUEOR( [Boolean_Expression_1], [Boolean_Expression_2], ... )OR( [Measures].[Sales] > 5000, [Time].[1997].[Q1] )
NOTReturns the opposite value of a single Boolean expressionNOT( [Boolean_Expression] )NOT( [Measures].[Sales] > 5000 )
EMPTYReturns TRUE if the calculated result of an expression is empty, otherwise returns FALSEEMPTY( [Value] )EMPTY( [Measures].[Sales])
EXISTINGReturns members from a specified dimension that already exist in the current contextEXISTING( [Set_Expression] )EXISTING( [Customers].[USA].[CA] )
NONEMPTYCROSSJOINReturns the Cartesian product of non-empty members for specified dimensionsNONEMPTYCROSSJOIN( [Set_Expression_1], [Set_Expression_2], ... )NONEMPTYCROSSJOIN( { [Customers].[USA].[CA], [Customers].[USA].[WA] }, { [Time].[1997].[Q1], [Time].[1997].[Q2] } )
TUPLETOSETConverts a tuple to a setTUPLETOSET( [Tuple_Expression] )TUPLETOSET( ( [Customers].[USA].[CA], [Time].[1997].[Q1] ) )

Note: BOOLEAN_EXPRESSION parameter refers to an expression that returns either TRUE or FALSE, such as [Measures].[Sales] > 5000.

String Functions

Function NameDescription and ExplanationSyntaxExample
CONCATReturns the concatenation of two stringsCONCAT( [String_Expression_1], [String_Expression_2] )CONCAT( "Hello", "World" )
LEFTReturns a specified number of characters from the left side of a stringLEFT( [String_Expression], [Numeric_Expression] )LEFT( "Hello", 3 )
RIGHTReturns a specified number of characters from the right side of a stringRIGHT( [String_Expression], [Numeric_Expression] )RIGHT( "Hello", 3 )
MIDReturns a specified number of characters from within a stringMID( [String_Expression], [Numeric_Expression_1], [Numeric_Expression_2] )MID( "Hello", 2, 3 )
STRCOMPCompares two strings and returns a value indicating whether they are equalSTRCOMP( [String_Expression_1], [String_Expression_2] )STRCOMP( "Hello", "HELLO" )
STRTODATEInterprets a string as a dateSTRTODATE( [String_Expression], [Format_String] )STRTODATE( "01/01/1997", "MM/DD/YYYY" )
LOWERConverts a string to lowercaseLOWER( [String_Expression] )LOWER( "HELLO" )
UPPERConverts a string to uppercaseUPPER( [String_Expression] )UPPER( "hello" )
STRLENReturns the length of a stringSTRLEN( [String_Expression] )STRLEN( "Hello" )
REPLACEReplaces specified characters in a stringREPLACE( [String_Expression], [Find_String], [Replace_String] )REPLACE( "Hello World", "World", "Mondrian" )
INSTRReturns the position of the first occurrence of a substring within a stringINSTR( [String_Expression], [Search_String] )INSTR( "Hello World", "World" )
LEFTSTRReturns a specified number of characters from the left side of a string (same as LEFT function)LEFTSTR( [String_Expression], [Numeric_Expression] )LEFTSTR( "Hello", 3 )

Math Functions

Function NameDescription and ExplanationSyntaxExample
ABSReturns the absolute value of an expressionABS( [Numeric_Expression] )ABS( -3 )
ROUNDReturns the rounded value of an expressionROUND( [Numeric_Expression] )ROUND( 3.14159, 2 )
CEILINGReturns the smallest integer greater than or equal to an expressionCEILING( [Numeric_Expression] )CEILING( 3.14159 )
FLOORReturns the largest integer less than or equal to an expressionFLOOR( [Numeric_Expression] )FLOOR( 3.14159 )
EXPReturns e raised to the power of an expressionEXP( [Numeric_Expression] )EXP( 2 )
LOGReturns the natural logarithm of an expressionLOG( [Numeric_Expression] )LOG( 10 )
POWERReturns the result of an expression raised to a specified powerPOWER( [Numeric_Expression_1], [Numeric_Expression_2] )POWER( 2, 3 )
SQRTReturns the square root of an expressionSQRT( [Numeric_Expression] )SQRT( 25 )
MODReturns the remainder of one number divided by anotherMOD( [Numeric_Expression_1], [Numeric_Expression_2] )MOD( 7, 3 )
SIGNReturns the sign of an expression (1: positive, -1: negative, 0: zero)SIGN( [Numeric_Expression] )SIGN( 3 )
SINReturns the sine of a specified angleSIN( [Numeric_Expression] )SIN( 45 )
COSReturns the cosine of a specified angleCOS( [Numeric_Expression] )COS( 45 )
TANReturns the tangent of a specified angleTAN( [Numeric_Expression] )TAN( 45 )
ASINReturns the arcsine of a specified numberASIN( [Numeric_Expression] )ASIN( 0.5 )
ACOSReturns the arccosine of a specified numberACOS( [Numeric_Expression] )ACOS( 0.5 )

Type Conversion

Function NameDescription and ExplanationSyntaxExample
CBOOLConverts an expression to Boolean typeCBOOL( [Value_Expression] )CBOOL( "True" )
CSTRConverts an expression to String typeCSTR( [Value_Expression] )CSTR( 3.14159 )
CINTConverts an expression to Integer typeCINT( [Value_Expression] )CINT( 3.14159 )
CDblConverts an expression to Double-precision floating-point typeCDbl( [Value_Expression] )CDbl( 3 )
CDECConverts an expression to Decimal type (Higher precision floating-point type)CDEC( [Value_Expression] )CDEC( 3.14159 )
CDATEConverts an expression to Date typeCDATE( [Value_Expression] )CDATE( "01/01/1997" )
CVARConverts an expression to Variant typeCVAR( [Value_Expression] )CVAR( "Hello" )
CBYTEConverts an expression to Byte type (integer between 0-255)CBYTE( [Value_Expression] )CBYTE( 255 )
CSHORTConverts an expression to Short type (integer between -32768 to 32767)CSHORT( [Value_Expression] )CSHORT( 32000 )
CLNGConverts an expression to Long type (integer between -2,147,483,648 to 2,147,483,647)CLNG( [Value_Expression] )CLNG( 2147483647 )
CSNGConverts an expression to Single type (Single-precision floating-point type between -3.402823E38 to 3.402823E38)CSNG( [Value_Expression] )CSNG( 3.14159 )
CBYTEConverts an expression to Byte type (integer between 0-255)CBYTE( [Value_Expression] )CBYTE( 255 )
CSTRTOSETConverts the specified string to a setCSTRTOSET( [String_Expression] )CSTRTOSET( "{ [Customers].[USA].[CA], [Customers].[USA].[WA] }" )