MDX:集合上的聚合

发布于 2024-08-25 16:02:05 字数 416 浏览 4 评论 0原文

我想要实现的目标看起来很简单,但我无法使其发挥作用。 我的事实是带有日期的订单,并且我有一个典型的时间维度,包括“月”和“年”级别。

我希望获得一个输出,其中列出了过去 6 个月的订单数和总数,如下所示:

Oct 2009   20
Nov 2009   30
Dec 2009   25
Jan 2009   15
Feb 2010   45
Mar 2010    5
Total     140  

我可以在 2009 年 10 月到 2010 年 3 月期间与成员一起创建该集合,并且我设法获得了我想要的输出的这一部分:

Oct 2009   20
Nov 2009   30
Dec 2009   25
Jan 2009   15
Feb 2010   45
Mar 2010    5

只是我无法获得总行。

What I am trying to achieves looks very simple, yet I cannot make it work.
My facts are orders which have a date and I have a typical time dimension with the 'Month" and 'Year' levels.

I would like to get an output which lists the number of orders for the last 6 months and the total, like this:

Oct 2009   20
Nov 2009   30
Dec 2009   25
Jan 2009   15
Feb 2010   45
Mar 2010    5
Total     140  

I can create the set with the members Oct 2009 until Mar 2010 and I manage to get this part of my desired output:

Oct 2009   20
Nov 2009   30
Dec 2009   25
Jan 2009   15
Feb 2010   45
Mar 2010    5

Just I fail to get the total line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2024-09-01 16:02:05

您可以通过将 ALL 成员添加到集合中,然后将其全部包装在 VisualTotals() 函数中来实现此目的

SELECT
  ... on COLUMNS,
  VISUALTOTALS (
       {[Month].[Month].[Oct 2009]:[Month].[Month].[Mar 2010] 
       , [Month].[Month].[All] } 
  ) ON ROWS
FROM <cube>

You can achieve this by adding the ALL member to the set and then wrapping it all in the VisualTotals() function

SELECT
  ... on COLUMNS,
  VISUALTOTALS (
       {[Month].[Month].[Oct 2009]:[Month].[Month].[Mar 2010] 
       , [Month].[Month].[All] } 
  ) ON ROWS
FROM <cube>
仙女山的月亮 2024-09-01 16:02:05

这是 Adventure Works DW Demo Cube 的一种可能的解决方案。该查询选择最后 6 个订单计数并在日期维度上添加总和:

WITH MEMBER [Date].[Calendar].[Last 6 Mth Order Count] AS 
aggregate( 
ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods]).Lag(6)
: ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods])

)
SELECT  {[Measures].[Order Count]} ON COLUMNS
, {ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods]).Lag(6)
: ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods])
,[Date].[Calendar].[Last 6 Mth Order Count]} 
ON ROWS
FROM [Adventure Works]

here is one possible solution for Adventure Works DW Demo Cube. The query selects the last 6 Order Counts and add a sum on the date dimension:

WITH MEMBER [Date].[Calendar].[Last 6 Mth Order Count] AS 
aggregate( 
ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods]).Lag(6)
: ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods])

)
SELECT  {[Measures].[Order Count]} ON COLUMNS
, {ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods]).Lag(6)
: ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[All Periods])
,[Date].[Calendar].[Last 6 Mth Order Count]} 
ON ROWS
FROM [Adventure Works]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文