在 SSAS 中,跨月和年时无法使 ParallelPeriod 函数起作用

发布于 2024-10-23 14:00:34 字数 1426 浏览 3 评论 0原文

我正在 Analysis Services 2008R2 中针对 Adventure Works 多维数据集构建 MDX 请求。我想要在行中获取月份,在列中获取年份,以便结果看起来像:

          2005 | 2006 | 2007 | ...
January    ... |  ... |  ... | ...
February   ... |  ... |  ... | ...
March      ... |  ... |  ... | ...
...

以下请求工作正常:

SELECT 
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount] } ) ON COLUMNS
FROM [Adventure Works]

现在,我想将当月的销售额与上个月的销售额进行比较:

               2005                ||      2006                || ...
          Sales | Sales prev month || Sales | Sales prev month ||...
January     ... |              ... ||   ... |              ... || ...
February    ... |              ... ||   ... |              ... || ...
March       ... |              ... ||   ... |              ... || ...
...

我使用以下命令编写了一个请求ParallelPeriod 函数:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], ParallelPeriod([Date].[Calendar].[Month], 1))
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month] } ) ON COLUMNS
FROM [Adventure Works]

问题是我得到的 [Sales Amount Prev Month] 度量值为 NULL。

看起来,尽管每个单元格代表一个月和一年,SSAS 似乎无法确定当前的 [日期].[日历].[月] 成员。然后,ParallelPeriod 无法获取上个月。

关于如何使 ParallelPeriod 函数在这种情况下工作有什么想法吗?非常感谢。

I am building an MDX request against the Adventure Works cube in Analysis Services 2008R2. I want to get months in rows and years in columns so that the result looks like:

          2005 | 2006 | 2007 | ...
January    ... |  ... |  ... | ...
February   ... |  ... |  ... | ...
March      ... |  ... |  ... | ...
...

The following request works fine:

SELECT 
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount] } ) ON COLUMNS
FROM [Adventure Works]

Now, I would like to compare the sales of the current month with the sales of the previous month:

               2005                ||      2006                || ...
          Sales | Sales prev month || Sales | Sales prev month ||...
January     ... |              ... ||   ... |              ... || ...
February    ... |              ... ||   ... |              ... || ...
March       ... |              ... ||   ... |              ... || ...
...

I wrote a request using the ParallelPeriod function:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], ParallelPeriod([Date].[Calendar].[Month], 1))
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month] } ) ON COLUMNS
FROM [Adventure Works]

The issue is that I get NULL values for the [Sales Amount Prev Month] measure.

It looks like, in spite of the fact that each cell represents a month and year, SSAS does not seem to be able to determine the current [Date].[Calendar].[Month] member. Then, the ParallelPeriod does not manage to get the previous month.

Any idea on how to make the ParallelPeriod function work in that case? Many thanks.

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

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

发布评论

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

评论(2

完美的未来在梦里 2024-10-30 14:00:34

我收到了来自 Microsoft 的以下 MDX 查询:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], ParallelPeriod([Date].[Calendar].[Month], 1))
member measures.def2
as
([Measures].[Sales Amount], ParallelPeriod(
    [Date].[Calendar].[Month],
    1,         
    exists(
        descendants([Date].[Calendar].currentmember,[Date].[Calendar].[Month],SELF),
        [Date].[Month of Year].currentmember).item(0)
        )
)
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month],def2 } ) ON COLUMNS
FROM [Adventure Works]

它相当复杂,但似乎解决了问题。

I received the following MDX query from Microsoft:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], ParallelPeriod([Date].[Calendar].[Month], 1))
member measures.def2
as
([Measures].[Sales Amount], ParallelPeriod(
    [Date].[Calendar].[Month],
    1,         
    exists(
        descendants([Date].[Calendar].currentmember,[Date].[Calendar].[Month],SELF),
        [Date].[Month of Year].currentmember).item(0)
        )
)
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month],def2 } ) ON COLUMNS
FROM [Adventure Works]

It's quite complex but it seems to solve the issue.

泅渡 2024-10-30 14:00:34

怎么样:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], [Date].[Month of Year].CurrentMember.PrevMember),
FORMAT_STRING = "Currency"
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month] } ) ON COLUMNS
FROM [Adventure Works]

当您想要上一季度的相应月份时,可以使用平行期间。这里 PrevMember 应该足够了。

更新:根据您的评论,我尝试利用另一个解决方案已经存在的层次结构:

WITH 
MEMBER [Sales Amount Prev Month] AS 
    ([Measures].[Sales Amount], [Date].Calendar.currentMember.prevMember), 
FORMAT_STRING = "Currency"

SELECT
{[Date].[Calendar].[Month].Members} ON ROWS,
(  { [Measures].[Sales Amount], [Sales Amount Prev Month] } ) ON COLUMNS
FROM [Adventure Works]

What about:

WITH MEMBER [Sales Amount Prev Month] AS ([Measures].[Sales Amount], [Date].[Month of Year].CurrentMember.PrevMember),
FORMAT_STRING = "Currency"
SELECT
[Date].[Month of Year].CHILDREN ON ROWS,
( [Date].[Calendar Year].CHILDREN, { [Measures].[Sales Amount], [Sales Amount Prev Month] } ) ON COLUMNS
FROM [Adventure Works]

Parallel period is used when you want the corresponding month in the previous quarter. Here PrevMember should be enough.

Update: following your comment I tried to exploit the hierarchies already present with another solution:

WITH 
MEMBER [Sales Amount Prev Month] AS 
    ([Measures].[Sales Amount], [Date].Calendar.currentMember.prevMember), 
FORMAT_STRING = "Currency"

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