如何在mdx中编写以下case语句。我在事实表中移动了下面提到的列。
sum(case when IsSummary = 1 and IsAudited = 1 and FinalAuditFlag = 1 then 1
else 0 end) AuditsCompleted,--Count - Completed Audits
我尝试了下面的MDX查询。
WITH
MEMBER [Measures].[count]
AS
(
case ([Measures].currentmember )
when 0 then ([Measures].[Is Summary] )
else 1
end
)
Select
{[Measures].[count]} on 0,
[Dim_table1].[TableId].members on 1
from [Dsv]
答案 0 :(得分:1)
你所做的几乎是正确的。只需将.currentmember
更改为多维数据集中的实际度量即可。目前,当您拥有以下内容时,它指的是自己,即currentmember
的黑色箭头,它指的是黑色箭头所示的度量count
...
这是AdvWrks
:
SELECT
{[Measures].[Internet Sales Amount]} ON 0
,{[Product].[Product Categories].[Category]} ON 1
FROM [Adventure Works];
它返回:
如果我想替换组件的空单元格,我们可以使用CASE
:
WITH
MEMBER [Measures].[count] AS
CASE [Measures].[Internet Sales Amount]
WHEN 0 THEN "XXX"
ELSE [Measures].[Internet Sales Amount]
END ,format_string = "#,###,##0"
SELECT
{
[Measures].[count]
} ON 0
,{[Product].[Product Categories].[Category]} ON 1
FROM [Adventure Works];
现在返回:
IIF
中使用的{p> MDX
比CASE
使用的更多 - IIF
几乎总是更快。因此,使用IIF
的上述等价物如下:
WITH
MEMBER [Measures].[count] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,"XXX"
,[Measures].[Internet Sales Amount]
)
,format_string = "#,###,##0"
SELECT
{[Measures].[count]} ON 0
,{[Product].[Product Categories].[Category]} ON 1
FROM [Adventure Works];
答案 1 :(得分:0)
我假设您的要求是找到[Dim Table1].[TableID]
层次结构的所有成员的总和。
如果那么,那么下面的内容对您有用: -
WITH MEMBER Measures.[Count] AS
SUM(
[Dim_table1].[TableId].CHILDREN,
[Measures].[Is Summary] * [Measures].[Is Audited] * [Measures].[Final Audited Flag] //If any is 0, it's 0, else 1
)
SELECT Measures.[Count]
FROM [Dsv]
如果需要添加更多切片器或者我的理解是不正确的,请告诉我。