我有一个与使用MDX创建一个(更有效)自定义不同计数度量有关的问题。
背景
我的立方体在事实和维度之间有几个长到多个关系链,对我来说重要的是能够跟踪哪些成员在某些维度中做和不与其他维度相关。因此,我在每个维度表中创建了一个“不相关”记录,并将这些记录的ID值设置为-1。然后,在我的中间映射事实表中,我使用-1 ID连接到这些“不相关”记录。
当我试图运行一个正常的开箱即用的独立计数时,问题就出现了,每个字段都存在-1成员。在a -1成员存在的情况下,不同的计数度量将返回比真实答案多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' ;The Issue
这个MDX工作并且总是显示正确的答案(是的!),但是当用户开始使用这个度量的几百个单元格的数据透视表时,它是非常慢的。对于少于100个细胞,结果几乎是即时的。对于几千个细胞(这一点并不少见),结果可能需要一个小时才能解决。
有人能告诉我如何写一个更有效的MDX公式来完成这个任务吗?您的帮助将不胜感激!!
乔恩·奥克代尔
jonoakdale@hotmail.com
琼恩
发布于 2015-01-16 12:25:00
您可以使用预定义的范围来取消所有不必要的(-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构造,因为不知道在您的情况下什么是维度/层次结构/所有级别的。[PID Used For MDX]似乎是所有级别的,[Providers]是维度和层次结构的名称,HierarchyUniqueName设置为隐藏。
https://stackoverflow.com/questions/27974649
复制相似问题