案例 MDX 中的多个语句
Posted
技术标签:
【中文标题】案例 MDX 中的多个语句【英文标题】:Multiple statements in case MDX 【发布时间】:2016-04-15 11:40:50 【问题描述】:我必须编写 MDX,它将显示在列上并将行分为三组。第一组以少数数字区分,第二组以属性区分,第三组是其余不适合的地方。
到目前为止,我的代码看起来像这样:
case
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "9378793737" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "3789789397" then "ABC"
when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
else "Rest"
end
但我每次都在“休息”。
我应该如何纠正?
编辑: 再次尝试但仍然无法正常工作:
case
when [Customer].[Customer's Document].[&5196189651] then "ABC"
when [Customer].[Customer's Document].[&7885181585] then "ABC"
when [Customer].[Customer's Document].[&7511535861] then "ABC"
when [Customer].[Customer's Document].[&4742575277] then "ABC"
when [Customer].[Customer's Document].[&7272727272] then "ABC"
when [Customer's Document].[Document Series].[&CHP] then "XYZ"
else "Rest"
end
【问题讨论】:
客户文档的值、键和名称属性是什么?客户维度的结构是什么?您如何查询此度量并将“其余”视为您的最终结果?请将查询添加到您的问题中,以便我们提供帮助。 @Dodzik - 维度[Customer]
在最终的 SELECT 子句的行上?!如果它不在行上,则 Currentmember 是 All 成员 ....currentmember 仅在维度实际上是 current 时起作用,即在上下文中。这可能是你一直休息的原因。你可以添加你的 mdx 脚本的其余部分吗?
【参考方案1】:
我感觉你想做一些类似以下的事情:
WITH
SET [ABC] AS
[Customer].[Customer's Document].&[5196189651]
,[Customer].[Customer's Document].&[7885181585]
,[Customer].[Customer's Document].&[7511535861]
,[Customer].[Customer's Document].&[4742575277]
,[Customer].[Customer's Document].&[7272727272]
MEMBER [Customer].[All].[ABC] AS
Aggregate([ABC])
MEMBER [Customer].[All].[XYZ] AS
[Customer].[Customer's Document].[Document Series].&[CHP]
SET [REST] AS
Except
(
[Customer].[Customer's Document].MEMBERS
,[ABC]
)
MEMBER [Customer].[All].[Rest] AS
Aggregate([REST])
SET [FINAL] AS
[Customer].[All].[ABC]
,[Customer].[All].[XYZ]
,[Customer].[All].[Rest]
SELECT
[FINAL] ON 1
,[Measures].[Amount] ON 0
FROM [YourCube];
或者可能是以下内容:
WITH
SET [ABC] AS
[Customer].[Customer's Document].&[5196189651]
,[Customer].[Customer's Document].&[7885181585]
,[Customer].[Customer's Document].&[7511535861]
,[Customer].[Customer's Document].&[4742575277]
,[Customer].[Customer's Document].&[7272727272]
MEMBER [Customer].[All].[ABC] AS
Aggregate([ABC])
MEMBER [Customer].[All].[XYZ] AS
[Customer].[Customer's Document].[Document Series].&[CHP]
SET [REST] AS
Except
(
[Customer].[Customer's Document].MEMBERS
,
[ABC]
,[Customer].[Customer's Document].[Document Series].&[CHP]
)
MEMBER [Customer].[All].[Rest] AS
Aggregate([REST])
SET [FINAL] AS
[Customer].[All].[ABC]
,[Customer].[All].[XYZ]
,[Customer].[All].[Rest]
SELECT
[FINAL] ON 1
,[Measures].[Amount] ON 0
FROM [YourCube];
编辑
只是一个警告 - 在接受的答案中有以下mdx
:
case
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739" then "ABC"
...
...
这可能被标记为解决方案,但不是很好mdx
。在这种情况下,应该使用IS
运算符:
case
when [Customer].[Customer's Document].CURRENTMEMBER IS
[Customer].[Customer's Document].[Customer's Document].&[4254255527] then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER IS
[Customer].[Customer's Document].[Customer's Document].&[2752637520] then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER IS
[Customer].[Customer's Document].[Customer's Document].&[5637839739] then "ABC"
...
...
【讨论】:
您的意思是在括号外加“&”吗[客户].[客户文档].&[7272727272] @Ala 我刚刚从原始问题中复制了成员名称,但是您是对的,&
通常在大括号之外。
@Dodzik - 我觉得这被错误地标记了,因为 Proffesore 的答案中的一般 mdx 不是很好 - 这样做 t].CURRENTMEMBER.MEMBERVALUE = "4254255527"
是使用 IS
运算符的一个糟糕的选择【参考方案2】:
您使用的是哪种 BI 工具;您可以将此作为名称计算添加到数据源视图中的新列(右键单击客户表->新建命名计算->列名:XXX)。 示例:
CASE
WHEN ACOLUMN BETWEEN 0 AND 10 THEN 'ABC'
WHEN ACOLUMN BETWEEN 10 AND 20 THEN 'ABC'
ELSE 'REST'
END
我相信在这种情况下你必须使用相同的层次结构。或者你可以将你的代码分成两部分:
case
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "9378793737" then "ABC"
when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "3789789397" then "ABC"
when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
else "Rest"
end
CASE
when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
else "Rest"
end
【讨论】:
以上是关于案例 MDX 中的多个语句的主要内容,如果未能解决你的问题,请参考以下文章