慢速 MDX 自定义非重复计数公式
Slow MDX Custom Distinct Count Formula
我有一个关于使用 MDX 创建(更有效的)自定义 Distinct Count Measure 的问题。
背景
我的多维数据集在事实和维度之间有几个很长的多对多关系链,能够跟踪某些维度中的哪些成员与其他维度相关和不相关对我来说很重要。因此,我在每个维度表中创建了一条 "Not Related" 记录,并将这些记录的 ID 值设置为 -1。然后在我的中间映射事实表中,我使用 -1 ID 连接到这些 "Not Related" 记录。
当我尝试在存在 -1 成员的任何字段上 运行 一个正常的开箱即用的非重复计数时,问题就出现了。在存在 -1 成员的情况下,非重复计数度量将 return 结果比真实答案多 1。
为了解决这个问题,我编写了以下 MDX:
CREATE MEMBER CURRENTCUBE.[Measures].[Provider DCount]
AS
//Oddly enough MDX seems to require that the PID (Provider ID) field be different from both the linking field and the user sliceable field.
SUM( [Providers].[PID Used For MDX].Children ,
//Don't count the 'No Related Record' item.
IIF( NOT([Providers].[PID Used For MDX].CURRENTMEMBER IS [Providers].[PID Used For MDX].&[-1])
//For some reason this seems to be necessary to calculate the Unknown Member correctly.
//The "Regular Provider DCount Measure" below is the out-of-the-box, non-MDX measure built off the same field, and is not shown in the final output.
AND [Measures].[Regular Provider DCount Measure] > 0 , 1 , NULL )
),
VISIBLE = 1 , DISPLAY_FOLDER = 'Distinct Count Measures' ;
问题
此 MDX 有效并且始终显示正确答案(是的!),但是当用户开始拉取包含超过数百个使用此度量的单元格的数据透视表时,它会非常慢。对于少于 100 个细胞,结果几乎是即时的。对于几千个细胞(这并不罕见),结果可能需要长达一个小时才能解决(uggghhh!)。
任何人都可以帮助我展示如何编写更高效的 MDX 公式来完成此任务吗?非常感谢您的帮助!!
乔恩·奥克代尔
jonoakdale@hotmail.com
乔恩
您可以使用预定义的范围来取消所有不必要的 (-1) 成员,然后创建您的度量。
SCOPE ([Providers].[PID Used For MDX].&[-1]
,[Measures].[Regular Provider DCount Measure]);
THIS = NULL;
END SCOPE;
CREATE MEMBER CURRENTCUBE.[Measures].[Provider DCount]
AS
SUM([Providers].[PID Used For MDX].Children
,[Measures].[Regular Provider DCount Measure]),
VISIBLE = 1;
顺便说一句,我在测试中使用了 [Providers].[PID Used For MDX].[All].Children
构造,因为不知道在您的情况下维度/层次结构/ALL-level 是什么。似乎 [PID Used For MDX]
是所有级别,[Providers]
是维度和层次结构的名称,并且 HierarchyUniqueName 设置为 Hide.
我有一个关于使用 MDX 创建(更有效的)自定义 Distinct Count Measure 的问题。
背景
我的多维数据集在事实和维度之间有几个很长的多对多关系链,能够跟踪某些维度中的哪些成员与其他维度相关和不相关对我来说很重要。因此,我在每个维度表中创建了一条 "Not Related" 记录,并将这些记录的 ID 值设置为 -1。然后在我的中间映射事实表中,我使用 -1 ID 连接到这些 "Not Related" 记录。
当我尝试在存在 -1 成员的任何字段上 运行 一个正常的开箱即用的非重复计数时,问题就出现了。在存在 -1 成员的情况下,非重复计数度量将 return 结果比真实答案多 1。
为了解决这个问题,我编写了以下 MDX:
CREATE MEMBER CURRENTCUBE.[Measures].[Provider DCount]
AS
//Oddly enough MDX seems to require that the PID (Provider ID) field be different from both the linking field and the user sliceable field.
SUM( [Providers].[PID Used For MDX].Children ,
//Don't count the 'No Related Record' item.
IIF( NOT([Providers].[PID Used For MDX].CURRENTMEMBER IS [Providers].[PID Used For MDX].&[-1])
//For some reason this seems to be necessary to calculate the Unknown Member correctly.
//The "Regular Provider DCount Measure" below is the out-of-the-box, non-MDX measure built off the same field, and is not shown in the final output.
AND [Measures].[Regular Provider DCount Measure] > 0 , 1 , NULL )
),
VISIBLE = 1 , DISPLAY_FOLDER = 'Distinct Count Measures' ;
问题
此 MDX 有效并且始终显示正确答案(是的!),但是当用户开始拉取包含超过数百个使用此度量的单元格的数据透视表时,它会非常慢。对于少于 100 个细胞,结果几乎是即时的。对于几千个细胞(这并不罕见),结果可能需要长达一个小时才能解决(uggghhh!)。
任何人都可以帮助我展示如何编写更高效的 MDX 公式来完成此任务吗?非常感谢您的帮助!!
乔恩·奥克代尔
jonoakdale@hotmail.com
乔恩
您可以使用预定义的范围来取消所有不必要的 (-1) 成员,然后创建您的度量。
SCOPE ([Providers].[PID Used For MDX].&[-1]
,[Measures].[Regular Provider DCount Measure]);
THIS = NULL;
END SCOPE;
CREATE MEMBER CURRENTCUBE.[Measures].[Provider DCount]
AS
SUM([Providers].[PID Used For MDX].Children
,[Measures].[Regular Provider DCount Measure]),
VISIBLE = 1;
顺便说一句,我在测试中使用了 [Providers].[PID Used For MDX].[All].Children
构造,因为不知道在您的情况下维度/层次结构/ALL-level 是什么。似乎 [PID Used For MDX]
是所有级别,[Providers]
是维度和层次结构的名称,并且 HierarchyUniqueName 设置为 Hide.