MDX:如何获取最大值和每天出现最大值的小时

时间:2019-03-24 14:23:46

标签: grouping mdx ranking

我有一个定义了小时尺寸的多维数据集,并且在事实表中有一个名为numberofoccurrances的列。如何获得最大次数以及每天发生该值的小时数。我尝试了以下

SELECT [Measures].[numberofoccurrances] ON 0,
TOPCOUNT([Hour].[Hour].MEMBERS, 1, [Measures].[numberofoccurrances])
ON 1
FROM [all_measurements]

查找出现最大值的小时,但将该小时的所有值相加并返回错误的值。

是否有办法在两列中获得一天的每小时最高价值?

1 个答案:

答案 0 :(得分:0)

您需要使用rank()和filter函数。看下面的例子。

下面的查询列出了年月的互联网销售量

SELECT 
{[Measures].[Internet Sales Amount]} ON COLUMNS,
non empty ({[Date].[Calendar Year].[CY 2011],[Date].[Calendar Year].[CY 2012],[Date].[Calendar Year].[CY 2013]},[Date].[Month of Year].[Month of Year])
ON ROWS 
FROM
[Adventure Works]

结果 enter image description here

现在对年份中的月份进行排名,并过滤第一兰特

WITH 
MEMBER [Measures].[Monthly_Ranking_InternetSales] AS
RANK( [Date].[Month of Year].CurrentMember,
ORDER( [Date].[Month of Year].[Month of Year].Members , [Measures].[Internet Sales Amount], BDESC)
) 
SELECT 
{[Measures].[Internet Sales Amount]} ON COLUMNS,
non empty
filter( ({[Date].[Calendar Year].[CY 2011],[Date].[Calendar Year].[CY 2012],[Date].[Calendar Year].[CY 2013]},
ORDER  ([Date].[Month of Year].[Month of Year], [Measures].[Monthly_Ranking_InternetSales] , BASC ) 
),[Measures].[Monthly_Ranking_InternetSales] <2)
ON ROWS 
FROM
[Adventure Works]

结果

enter image description here