MDX - Running Sum over months limited to an interval

依然范特西╮ 提交于 2019-12-11 14:38:06

问题


I have a query that after some sweating and some swearing works

WITH
    MEMBER [Measures].[m_active] AS ([Measures].[CardCount], [Operation].[Code].[ACTIVATION])
    MEMBER [Measures].[m_inactive] AS ([Measures].[CardCount], [Operation].[Code].[DEACTIVATION])
    MEMBER [Measures].[p_active] AS 
    SUM(
        [Calendar.YMD].[2016].[January]:[Calendar.YMD].CurrentMember, 
        [Measures].[m_active]
    )
    MEMBER [Measures].[p_inactive] AS
    SUM(
        [Calendar.YMD].[2016].[January]:[Calendar.YMD].CurrentMember, 
        [Measures].[m_inactive]
    )
    MEMBER [Measures].[tot_active] AS (
        SUM({[Calendar.YMD].[2010].Children}.Item(0):[Calendar.YMD].CurrentMember, [Measures].[m_active]) - 
        SUM({[Calendar.YMD].[2010].Children}.Item(0):[Calendar.YMD].CurrentMember, [Measures].[m_inactive])
    )
    MEMBER [Measures].[p_tot_active] AS 
    SUM(
        [Calendar.YMD].[2016].[January]:[Calendar.YMD].CurrentMember, 
        [Measures].[tot_active]
    )
SELECT
    {[Measures].[m_active], [Measures].[p_active], [Measures].[m_inactive], [Measures].[p_inactive], [Measures].[tot_active], [Measures].[p_tot_active]} ON COLUMNS,
    NonEmptyCrossJoin(
        {Descendants([Calendar.YMD].[2016].[January]:[Calendar.YMD].[2017].[August], [Calendar.YMD].[Month])},
        {Descendants([CardStatus.Description].[All CardStatus.Descriptions], [CardStatus.Description].[Description])}
    ) on ROWS
FROM [Cube]

What I obtain is a table that for each months show the activation and deactivation relative to that month, the accumulated activations relative to the period considered (starting from 1 January 2016 and ending 1 August 2017) and the total active cards from the beginning of time (january 2010) until the end time interval.

This interval is parametrized and the day are to be considered, with this query all the activations made in august are considered even the ones made after the 1st.

I try to make some modifications like this.

WITH
    MEMBER [Measures].[m_active] AS ([Measures].[CardCount], [Operation].[Code].[ACTIVATION])
    MEMBER [Measures].[m_inactive] AS ([Measures].[CardCount], [Operation].[Code].[DEACTIVATION])
    MEMBER [Measures].[p_active] AS 
    SUM(
        [Calendar.YMD].[2016].[January].[1]:[Calendar.YMD].CurrentMember, 
        [Measures].[m_active]
    )
    MEMBER [Measures].[p_inactive] AS
    SUM(
        [Calendar.YMD].[2016].[January].[1]:[Calendar.YMD].CurrentMember, 
        [Measures].[m_inactive]
    )
    MEMBER [Measures].[tot_active] AS (
        SUM({[Calendar.YMD].[2010].[January].Children}.Item(0):[Calendar.YMD].CurrentMember, [Measures].[m_active]) - 
        SUM({[Calendar.YMD].[2010].[January].Children}.Item(0):[Calendar.YMD].CurrentMember, [Measures].[m_inactive])
    )
    MEMBER [Measures].[p_tot_active] AS 
    SUM(
        [Calendar.YMD].[2016].[January].[1]:[Calendar.YMD].CurrentMember, 
        [Measures].[tot_active]
    )
SELECT
    {[Measures].[m_active], [Measures].[p_active], [Measures].[m_inactive], [Measures].[p_inactive], [Measures].[tot_active], [Measures].[p_tot_active]} ON COLUMNS,
    NonEmptyCrossJoin(
        {Descendants([Calendar.YMD].[2016].[January]:[Calendar.YMD].[2017].[August], [Calendar.YMD].[Month])},
        {Descendants([CardStatus.Description].[All CardStatus.Descriptions], [CardStatus.Description].[Description])}
    ) on ROWS
FROM [Cube]

But I get this error on the relative fields:

#ERR: mondrian.olap.fun.MondrianEvaluationException: Members must belong to the same level

How can i solve this? Thanks.

来源:https://stackoverflow.com/questions/46182130/mdx-running-sum-over-months-limited-to-an-interval

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!