Navigating Subtle Time Dimension Challenges in MDX: A Multi-Hierarchy Case Study

Nathalie Leroy
Nathalie Leroy
March 21, 2025

This is a very advanced MDX example encountered with one of our customers. Note it uses a functionality of icCube that allows for a tuple to have the same hierarchy multiple times defined.

TABLE OF CONTENTS
Grok AI-generated pink cubes
OLAP
Analytics

We present here an example of a very advanced MDX that we encountered with one of our customers. Note it uses a functionality of icCube that allows for a tuple to have the same hierarchy multiple times defined.

The use case

The use case involves multiple time hierarchies within a single time dimension in a non standard way.

The simplified structure is as follows:

  • Dimension: Calendar
    • Hierarchy: Year
      • Level: Year
    • Hierarchy: Period
      • Level: Period Value (PV)
      • Level: Period (P)

Period hierarchy example (PV & P children): 

  • 1
    • P1 2024
    • P1 2025
    • P1 2026
  • 2
    • P2 2024
    • P2 2025
    • P2 2026

The goal is to compute Sales for the previous year while displaying Year, PV, and P. Here’s the initial query:

WITH

 MEMBER [Measures].[Sales Prev Year] AS ([Calendar].[Year].currentMember.prevMember,  [Measures].[Sales])

SELECT

 { [Measures].[Sales], [Measures].[Sales Prev Year] } on 0

 [Calendar].[Year].[Year] * 

 [Calendar].[Period].[PV] * 

 [Calendar].[Period].[P] on 1

 [Product].[Product].[Product] on 2

FROM [Cube]

In our example we are looking to have something like:

2024 2025
P1 2024 P1 2025
Sales Sales Prev-Year Sales Sales Prev-Year
Product 1 8 5 10 8

But what we got:

2024 2025
P1 2024 P1 2025
Sales Sales Prev-Year Sales Sales Prev-Year
Product 1 8 <empty> 10 <empty>

What happened here?

Since Year and Period are separate hierarchies, the expression 

([Calendar].[Year].currentMember.prevMember,  [Measures].[Sales])

becomes (after completion from the context defined from the axes):

([Calendar].[Year].currentMember.prevMember, [Calendar].[Period].[PV].[1], [Calendar].[Period].[P].[P1 2025], [Measures].[Sales])

Why? 

‍MDX retained the current context of [P1 2025] from the axis, pairing it with the prior year [2024]. Since [P1 2025] doesn’t exist under [Year].[2024] in the cube, the result was <empty> instead of 8.

We got:

  • Actual: ([Calendar].[Year].[2024], [Calendar].[Period].[PV].[1], [Calendar].[Period].[P].[P1 2025], [Measures].[Sales])
  • Expected: ([Calendar].[Year].[2024], [Calendar].[Period].[PV].[1], [Measures].[Sales])

Visually:

  • Actual: prevMember of [2025] * [1] * [P1 2025] became [2024] * [1] * [P1 2025]
  • Expected: prevMember of [2025] * [1] * [P1 2025] should be [2024] * [1] (which corresponds to [2024] * [1] * [P1 2024] as there is only one child [P] of [PV] for each year. This is due to the construction of the hierarchy).

What we need to do

Keep [Calendar].[Period].[PV].[1] and reset [Calendar].[Period].[P].[P1 2025]

Solution

Specify the Period’s currentMember to override the default:

WITH
 MEMBER [Measures].[Sales Prev Year] AS ([Calendar].[Year].currentMember.prevMember, [Calendar].[Period].currentMember(0), [Measures].[Sales])‍

SELECT
 { [Measures].[Sales], [Measures].[Sales Prev Year] } on 0
 [Calendar].[Year].[Year] * [Calendar].[Period].[PV] * [Calendar].[Period].[P] on 1
 [Product].[Product].[Product] on 2
FROM [Cube]

As read in the currentMember doc:

Since icCube 4.8, this function returns a set of members if the tuple contains two members of the same hierarchy. This functionality needs the 'dimensionalityCheck' icCube property set to false.

That’s why we need to retrieve [Calendar].[Period].currentMember(0)

So (0) corresponds to the first item which is [Calendar].[Period].[PV].[1]. By doing so, it overrides all other members of the hierarchy, therefore resetting [Calendar].[Period].[P].[P1 2025].

Things to take into account:

  • You can use the same hierarchy in one or multiple axes but it might complicate your calculations.
  • In this scenario, currentMember returns a set.

This subtle, advanced scenario highlights how hierarchy interactions can silently skew results. Tools like an MDX debugger are invaluable for tracing such calculations step-by-step.

You find our Articles Helpful?
Subscribe to our Newsletter to never miss One!