我有一个MDX查询,它返回了2个不同的值,查找总数和查找失败次数(以及其他一些内容,但这是重要的部分)。
with
member [Pct Success] as 'iif(isempty([Num Lookup]) or [Num Lookup]=0, null,
100 * (coalesceempty([Num Lookup] - [Num Failed], 0) / [Num Lookup]))'
select
{
[Measures].[Pct Success],
[Measures].[Num Lookup],
[Measures].[Num Failed]
} on 0,
[Calendar].[Date].children on 1
from
[Cube]
现在我要做的是获得另一次成功测量,但我希望这个能够抑制低于特定阈值的任何[Num Failed]单元格。具体来说,如果我至少有4次成功查找(Num Lookup - Num Failed> 3&& Num Lookup> 4),那么我想让那个单元格[Num Failed] = 0(或者更确切地说)我想制作[Num Failed] = 0的副本,因为我仍然需要显示原始的%Success度量。)
基本事实看起来像这样(只是列的相关子集 - 行列是为了便于参考,它不在实际的事实中):
Line | CalendarKey | Num Failed | Num Lookup 1 | 20130601 | 2 | 8 2 | 20130601 | 5 | 8 3 | 20130601 | 1 | 8 4 | 20130601 | 0 | 7 5 | 20130601 | 7 | 8 6 | 20130602 | 2 | 6 7 | 20130602 | 1 | 7 8 | 20130602 | 5 | 10 9 | 20130602 | 7 | 9 etc.
基于上述事实,我希望看到的结果是:
| % Success | % Filt Success | Num Filt Failed | Num Failed | Num Lookup 20130601 | 61.53 | 69.23 | 12 | 15 | 39 20130602 | 53.13 | 71.88 | 9 | 15 | 32
在上述事实样本中,第1,3,4,7和1行。 8所有过滤失败的值都为0,这为我们提供了上面列出的样本输出。
我最初的想法是使用with子句中的另一个成员作为[Num Failed]的副本,然后使用Cell Calculation来进行抑制,但我无法使Cell Calculation正常工作 - 它要么不会修改该值,也不会在评估期间出错。
这是"应该"的非工作版本。返回我正在寻找的东西,但不是:
with
member [Measures].[Num Threshold Failure] AS [Num Failed]
Cell Calculation [Data Filter] For '[Measures].[Num Threshold Failure]' AS 'NULL', Condition = 'CalculationPassValue((([Measures].[Num Lookup] - [Measures].[Num Failure]) < 4) AND ([Measures].[Num Lookup] > 4), 1)'
member [Pct Success] as 'iif(isempty([Num Lookup]) or [Num Lookup]=0, null, 100 * (coalesceempty([Num Lookup] - [Num Failed], 0) / [Num Lookup]))'
member [Pct Filtered Success] as 'iif(isempty([Num Lookup]) or [Num Lookup]=0, null, 100 * (coalesceempty([Num Lookup] - [Num Threshold Failure], 0) / [Num Lookup]))'
select
{
[Measures].[Pct Success],
[Measures].[Pct Filtered Success],
[Measures].[Num Threshold Failure],
[Measures].[Num Failed],
[Measures].[Num Lookup]
} on 0,
{ [Calendar].[Date].children } on 1
from
[Cube]
答案 0 :(得分:3)
我不清楚你的问题的每一个细节,但据我所知,以下内容应该回答,或至少接近:
with
member [Pct Success] as iif([Measures].[Num Lookup]=0,
null,
100 * (coalesceempty([Measures].[Num Lookup] -[Measures]. [Num Failed], 0) / [Measures].[Num Lookup]))
member [Filtered Failed] as iif([Measures].[Num Lookup] - [Measures].[Num Failed] > 3 and [Measures].[Num Lookup] > 4),
0,
[Measures].[Num Failed])
member [Bottom Filtered failed] as Sum(Leaves(),
iif([Measures].[Num Lookup] - [Measures].[Num Failed] > 3 and [Measures].[Num Lookup] > 4),
0,
[Measures].[Num Failed]))
member [Pct Filtered Success] as iif([Measures].[Num Lookup]=0,
null,
100 * (coalesceempty([Measures].[Num Lookup] -[Measures]. [Filtered Failed], 0) / [Measures].[Num Lookup]))
select
{
[Measures].[Pct Success],
[Measures].[Num Lookup],
[Measures].[Num Failed],
[Measures].[Num Filtered Failed],
[Measures].[Bottom Filtered Failed],
[Measures].[Pct Filtered Success]
} on 0,
[Calendar].[Date].children on 1
from [Cube]
BTW:除非您的目标是MDX的SQL Server 2000方言,否则不需要在单引号的WITH子句中包含成员定义。 并且,根据此blog post of the former lead developer of the MDX processor,您可以简化对空的检查,并将null简化为仅检查零。
修改强>
正如您所述,用户希望在假设分析中使用多种不同的公差,如果您的立方体不是很大,可以做些什么,而且不同公差的数量只是少数,您可以预先计算出 - 如果是案例,则使用Analysis Services的快速响应时间来计算聚合值。
为此,您将按以下步骤操作:构建一个小维度表,例如dim_tolerance,包含e。 G。数字0到10,或数字0,1,2,3,5,8,10和12,或任何有意义的数字。然后构建一个引用与当前维度相同的维度的新事实表,加上新的事实表,并用dim_tolerance值指示的单个度量[num failed filtered]填充它。然后,您可以从主事实表中删除[num failed]度量(因为它与[num failed filtered]相同,容差为0)。使新维度中的属性不可聚合,默认值为0.