具有多个标准的 MDX 案例陈述 "When"
MDX Case Statement With Multiple Criteria in single "When"
我正在尝试尽可能多地合并以下 MDX 脚本,想知道是否有办法将四个季度(Q1、Q2、Q3、Q4)合并为一行?另外,如果您对如何简化这个有任何进一步的想法,我洗耳恭听!
Case [Period].CurrentMember
When [Q1] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q2] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q3] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q4] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Total Year] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])
Else
[Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*12
End
这应该有效
Case
When [Period].CurrentMember =[Q1] or [Period].CurrentMember =[Q2] or [Period].CurrentMember =[Q3] or [Period].CurrentMember =[Q4]
Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Period].CurrentMember =[Total Year] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])
Else
[Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*12
End
下面是另一个基于冒险作品的示例,对您有所帮助。
with member measures.test as
case
when
[Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="caps"
or [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="chains"
or [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="gloves"
then 1
when [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="Fenders"
then 5
else 0 end
select {[Measures].[Internet Sales Amount],measures.test} on columns ,
[Product].[Subcategory].[Subcategory] on rows
from
[Adventure Works]
IS
运算符是您的朋友:我不确定 =
运算符是否有效,使用 ....Properties ("Member_Value",TYPED) ="caps"
很慢。
我还尝试使用 IIF
,在 MDX
中,它通常比 CASE
快
IIF(
( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )*4
)
, IIF(
( [Period].CURRENTMEMBER IS [Period].[Period].[Total Year] )
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )
)
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )*12
)
)
编辑
使用 IIF/IS 进行更复杂的查询会更快 - 这相当于 MoazRubs AdvWrks 脚本:
WITH
MEMBER measures.test as
IIF(
[Product].[Subcategory].currentmember IS [Product].[Subcategory].[Caps]
OR [Product].[Subcategory].currentmember IS [Product].[Subcategory].[Chains]
OR [Product].[Subcategory].currentmember IS [Product].[Subcategory].[Gloves]
, 1
, IIF(
[Product].[Subcategory].currentmember IS [Product].[Subcategory].[Fenders]
,5
,NULL
)
)
SELECT
{
[Measures].[Internet Sales Amount],
measures.test
} ON 0,
[Product].[Subcategory].[Subcategory] ON 1
FROM
[Adventure Works]
我正在尝试尽可能多地合并以下 MDX 脚本,想知道是否有办法将四个季度(Q1、Q2、Q3、Q4)合并为一行?另外,如果您对如何简化这个有任何进一步的想法,我洗耳恭听!
Case [Period].CurrentMember
When [Q1] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q2] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q3] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Q4] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Total Year] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])
Else
[Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*12
End
这应该有效
Case
When [Period].CurrentMember =[Q1] or [Period].CurrentMember =[Q2] or [Period].CurrentMember =[Q3] or [Period].CurrentMember =[Q4]
Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*4
When [Period].CurrentMember =[Total Year] Then [Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])
Else
[Finance Charge and NSF Revenue] / ([CXO_Average Total A/R]+[Average Total A/R - Normalized Load])*12
End
下面是另一个基于冒险作品的示例,对您有所帮助。
with member measures.test as
case
when
[Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="caps"
or [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="chains"
or [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="gloves"
then 1
when [Product].[Subcategory].currentmember.Properties ("Member_Value",TYPED) ="Fenders"
then 5
else 0 end
select {[Measures].[Internet Sales Amount],measures.test} on columns ,
[Product].[Subcategory].[Subcategory] on rows
from
[Adventure Works]
IS
运算符是您的朋友:我不确定 =
运算符是否有效,使用 ....Properties ("Member_Value",TYPED) ="caps"
很慢。
我还尝试使用 IIF
,在 MDX
中,它通常比 CASE
IIF(
( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
OR ( [Period].CURRENTMEMBER IS [Period].[Period].[Q1] )
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )*4
)
, IIF(
( [Period].CURRENTMEMBER IS [Period].[Period].[Total Year] )
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )
)
, DIVIDE(
[Finance Charge and NSF Revenue]
,( [CXO_Average Total A/R]+[Average Total A/R - Normalized Load] )*12
)
)
编辑
使用 IIF/IS 进行更复杂的查询会更快 - 这相当于 MoazRubs AdvWrks 脚本:
WITH
MEMBER measures.test as
IIF(
[Product].[Subcategory].currentmember IS [Product].[Subcategory].[Caps]
OR [Product].[Subcategory].currentmember IS [Product].[Subcategory].[Chains]
OR [Product].[Subcategory].currentmember IS [Product].[Subcategory].[Gloves]
, 1
, IIF(
[Product].[Subcategory].currentmember IS [Product].[Subcategory].[Fenders]
,5
,NULL
)
)
SELECT
{
[Measures].[Internet Sales Amount],
measures.test
} ON 0,
[Product].[Subcategory].[Subcategory] ON 1
FROM
[Adventure Works]