-->

MDX - Running Sum over months limited to an interv

2019-08-17 07:43发布

问题:

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.

标签: mdx mondrian