Question

So I have a value that represents the length in days on a fact table. I'd like to create queries that break that value out into N number of bands (say 4 bands) by year. Is there a way to do that with CalculatedMembers? For example, I'd like to have bands for: < 1 year, 1-3 years, 3-5 years, 5+ years. I could do it with days like:

0 - 365
365 - 1095
1096 - 1825
1826 - infinity

Any idea how to do this? I'm using Mondrian. I'd like to calculate it on the fly rather than adding a field and changing ETL scripts, etc.

I have a measure defined that represents the average length in days (displayed as 2.4 years) using the aggregation function. But really I want to define a completely new measure that is a calculated measure on that same column where a function returns which band it belongs in as above, then rolls up how many were in each band.

I'm beginning to suspect I have to do this in ETL and create a new column that places them in a band. This is really a new dimension I suspect (not so much a calculated measure).

Was it helpful?

Solution

I understand from your question that you want to have the bands as categories, which would mean you need them as members of some hierarchy. You can dynamically create members in MDX, but only for existing hierarchies. You did not state one, hence I just assume you have a hierarchy of events for which you want to seed cluster the duration, furthermore I assume the hierarchy containing the dimension key is named [Event].[Event Id]. You also dis not state the name of the "average duration" measure. hence I just assume it is called Duration.

Then you could use the following MDX:

WITH Member [Event].[Event Id].[< 1 year] AS
     Aggregate(Filter([Event].[Event Id].[Event Id].Members,
                      [Measures].[Duration] < 1.0
                     )
              )
     Member [Event].[Event Id].[1-3 years] AS
     Aggregate(Filter([Event].[Event Id].[Event Id].Members,
                      [Measures].[Duration] >= 1.0 AND [Measures].[Duration] < 3.0
                     )
              )
     Member [Event].[Event Id].[3-5 years] AS
     Aggregate(Filter([Event].[Event Id].[Event Id].Members,
                      [Measures].[Duration] >= 3.0 AND [Measures].[Duration] < 5.0
                     )
              )
     Member [Event].[Event Id].[5+ years] AS
     Aggregate(Filter([Event].[Event Id].[Event Id].Members,
                      [Measures].[Duration] >= 5.0
                     )
              )
SELECT ... // whatever you want to see
       ON COLUMNS,
       {
       [Event].[Event Id].[< 1 year],
       [Event].[Event Id].[1-3 years],
       [Event].[Event Id].[3-5 years],
       [Event].[Event Id].[5+ years]
       }
       ON ROWS
FROM [YourCube]

Add WHERE conditions, other hierarchies to the rows or columns, subselects as you like.

I am not sure if this is really fast, but it solves the question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top