Getting the total for last month in MDX

IIF(
        // Gets the last day of the last month when it is the last day of the current month.
        IsSibling(ParallelPeriod([Date].[Year Month Day].[Day], -1, [Date].[Year Month Day].CurrentMember),
         [Date].[Year Month Day].CurrentMember) AND
        IsLeaf(
            // Gets the last day of the month when the parallel day doesn’t exist.
            ParallelPeriod([Date].[Year Month Day].[Month], 1, [Date].[Year Month Day].CurrentMember)
            ),
        // Gets the same day last month
        ParallelPeriod([Date].[Year Month Day].[Month], 1, [Date].[Year Month Day].CurrentMember),
        // Gets the last day of last month
        ClosingPeriod(
            [Date].[Year Month Day].[Day],
            ParallelPeriod([Date].[Year Month Day].[Month], 1, [Date].[Year Month Day].CurrentMember.Parent)
            )
        ),
 [Measures].[Orders On Hand]

Advertisements