使用标量表达式

在多维表达式 (MDX) 中,标量表达式是 MDX 语法的一个元素;在计算时,它在计算上下文中返回单个值。

标量表达式包括 MDX 中的字符串表达式、数值表达式和日期表达式。

由于计算成员必须返回标量值,因此标量表达式通常用于计算成员定义。 以下查询说明 Measures 维度上使用不同类型标量表达式的计算成员的示例:

WITH

MEMBER MEASURES.NumericValue AS 10

MEMBER MEASURES.NumericExpression AS 10 + 10

MEMBER MEASURES.NumericExpressionBasedOnMeasure AS [Measures].[Internet Sales Amount] + 10

MEMBER MEASURES.StringValue AS "10"

MEMBER MEASURES.ConcatenatedString AS "10" + "10"

MEMBER MEASURES.StringFunction AS MEASURES.CURRENTMEMBER.NAME

MEMBER MEASURES.TodaysDate AS NOW()

SELECT

{MEASURES.NumericValue,MEASURES.NumericExpression,MEASURES.NumericExpressionBasedOnMeasure,

MEASURES.StringValue, MEASURES.ConcatenatedString, MEASURES.StringFunction, MEASURES.TodaysDate}

ON COLUMNS

FROM [Adventure Works]

度量值(计算度量值或其他度量值)可以返回的唯一数据类型是 OLE Variant 类型。 因此,有时可能需要将度量值转换为特定类型才能得到所需的行为。 以下查询说明此类情况的一个示例:

WITH  
//Two calculated measures that return strings  
MEMBER MEASURES.NumericString1 AS "10"  
MEMBER MEASURES.NumericString2 AS "10"  
//In this case, the + operator acts to concatenate the strings  
MEMBER MEASURES.Concatenation AS MEASURES.NumericString1 + MEASURES.NumericString2  
//Casting one value to an integer with the CINT function causes the second measure  
//to be treated as an integer too, so that the + operator now acts to add the values  
MEMBER MEASURES.Addition AS CINT(MEASURES.NumericString1) + MEASURES.NumericString2  
SELECT  
{MEASURES.NumericString1,MEASURES.NumericString2,MEASURES.Concatenation,MEASURES.Addition }  
ON COLUMNS  
FROM [Adventure Works]  

另请参阅

表达式 (MDX)