我对mdx很新,并且即将学习它。我现在遇到了麻烦,因为我想获得两个日期之间每个工作日的平均金额。 例如11月1日到12月1日之间有4个星期一,所以平均值是[Measures]。[Amount] / 4,但我真的无法弄清楚如何在MDX中表达这个简单的函数
with member [Measures].[Avg] as
avg([Dim Date].[Day Of Week].[Day Of Week]
, [Measures].[amount])
SELECT NON EMPTY { ([Measures].[Avg]), ([Measures].[Amount])} ON COLUMNS,
NON EMPTY { ([Dim Date].[Day Of Week].[Day Of Week].ALLMEMBERS * [Dim Date].[Date Int].[Date Int].ALLMEMBERS )}
ON ROWS FROM ( SELECT ( { [Dim Client].[Common Client UID].&[{xx}] } )
ON COLUMNS FROM ( SELECT ( [Dim Date].[Date Int].&[20151115] : [Dim Date].[Date Int].&[20151215] )
ON COLUMNS FROM [ff]))
WHERE ( [Dim Client].[Common Client UID].&[{xx}] )
此查询为我提供每个工作日以及绑定到特定工作日的所有日期,并且每个日期都有总金额。
就像你可以看到我的平均值与总数相同。我想我可以选择两个日期之间的所有工作日,例如找出有多少星期一,并将数量除以金额。但我也无法解决这个问题。
with member [Measures].[avg] as
avg([Dim Date].[Day Of Week].[Day Of Week], [Measures].[Amount])
SELECT NON EMPTY {[Measures].[avg], [Measures].[Amount]} ON COLUMNS, NON EMPTY { ([Dim Date].[Day Of Week].[Day Of Week].ALLMEMBERS )}
ON ROWS FROM ( SELECT ( { [Dim Client].[Common Client UID].&[{xx}] } )
ON COLUMNS FROM ( SELECT ( [Dim Date].[Date Int].&[20151115] : [Dim Date].[Date Int].&[20151215] )
ON COLUMNS FROM [ff]))
WHERE ( [Dim Client].[Common Client UID].&[{xx}] )
结果:
我如何解决这个问题?
答案 0 :(得分:1)
您真正想要的是在给定日期范围内与该工作日相对应的日期的平均金额。
您可以将日期范围移动到计算成员的定义,以便在评估特定工作日的值时,也会考虑日期范围。
with member [Measures].[Avg] as
avg
(
[Dim Date].[Day Of Week].CURRENTMEMBER * {[Dim Date].[Date Int].&[20151115] : [Dim Date].[Date Int].&[20151215]}
,[Measures].[amount]
)
SELECT NON EMPTY { ([Measures].[Avg]), ([Measures].[Amount])} ON COLUMNS,
NON EMPTY [Dim Date].[Day Of Week].[Day Of Week].ALLMEMBERS * [Dim Date].[Date Int].[Date Int].ALLMEMBERS ON ROWS
FROM [ff]
WHERE ( [Dim Client].[Common Client UID].&[{xx}] )