在 MDX 中使用“不同定义”计算相同度量的差异

Posted

技术标签:

【中文标题】在 MDX 中使用“不同定义”计算相同度量的差异【英文标题】:calculating the difference of the same measure with a 'different definition' in MDX 【发布时间】:2014-06-16 04:00:40 【问题描述】:

我想用“不同的定义”计算相同度量的差异 这是我尝试过的,但它不起作用:

 WITH MEMBER [Measures].[Births] AS 
'[Measures].[type], [dimType].[TypeL].[Births]' 
 MEMBER [Measures].[Deaths] AS 
'[Measures].[type], [dimType].[TypeL].[Deaths]' 
 MEMBER [Measures].[Population_Growth] AS 
'[Measures].[Births] - [Measures].[Deaths]' 
 SELECT [Measures].[Population_Growth] ON COLUMNS, 
 [dimTime].[year] ON ROWS FROM [Population]

运行此查询时,我每年都会得到 Population_Growth = 0。 我是 MDX 新手,不知道自己做错了什么?

【问题讨论】:

【参考方案1】:

不确定。在 MDX 中,您已经评估了一个元组。如果您只有一个成员,则不需要括号,但如果您有多个成员,则需要它们。可以试试吗

WITH 
  MEMBER [Measures].[Births] AS ([Measures].[type], [dimType].[TypeL].[Births]) 
  MEMBER [Measures].[Deaths] AS ([Measures].[type], [dimType].[TypeL].[Deaths]) 
  MEMBER [Measures].[Population_Growth] AS [Measures].[Births] - [Measures].[Deaths]
SELECT
 [Measures].[Population_Growth] ON COLUMNS, 
 [dimTime].[year] ON ROWS 
FROM [Population]

如果这不起作用,则可能是 [type] 度量:

WITH 
  MEMBER [Measures].[Births] AS ([Measures].defaultmember, [dimType].[TypeL].[Births]) 
  MEMBER [Measures].[Deaths] AS ([Measures].defaultmember, [dimType].[TypeL].[Deaths]) 
  MEMBER [Measures].[Population_Growth] AS [Measures].[Births] - [Measures].[Deaths]
SELECT
 [Measures].[Population_Growth] ON COLUMNS, 
 [dimTime].[year] ON ROWS 
FROM [Population]

如果这不起作用,我们可以检查成员 [dimType].[TypeL].[Births] 是否正常。

WITH 
  MEMBER [Measures].[Population_Growth] AS [dimType].[TypeL].[Births].name
SELECT
 [Measures].[Population_Growth] ON COLUMNS, 
 [dimTime].[year] ON ROWS 
FROM [Population]

应该返回 'Births'

【讨论】:

以上是关于在 MDX 中使用“不同定义”计算相同度量的差异的主要内容,如果未能解决你的问题,请参考以下文章

在 MDX 中为使用事实表中的相同列的不同度量构造计算度量

PY YTD 计算的可以处理闰年 MDX 的度量

通过过滤度量值在 MDX 中定义计算成员

如何在 MDX 中基于维度属性定义计算度量?

使用 where 子句 (MDX) 的 SSAS 计算度量

范围内总和计数的 MDX 计算