mondrian icon indicating copy to clipboard operation
mondrian copied to clipboard

Implement Existing Keyword

Open chubbard opened this issue 8 years ago • 5 comments

It's basically impossible to do anything moderately complex without the EXISTING keyword. I can't believe Mondrian is as old as it is and it's never been done.

MDX standard specifies the EXISTING keyword that can be used in WITH MEMBER calculations to use the existing context to limit a sets membership as opposed to using the cube's context. For example:

with member [Measures].[Employees] as
    'count( EXISTING [Employee].Members'
select
    { [Measures].[Employees] } on columns,
    { [employmentDate.yearMonth].[2010]:[employmentDate.yearMonth].[2012] } on rows
from [Workforce]

Now you can work around this little snafu using the Count( {}, EXCLUDEEMPTY ) trick like so:

with member [Measures].[Employees] as
   'Count(Distinct( [Employee].Members),EXCLUDEEMPTY) - Count(Distinct([Measures].[Terminations]),EXCLUDEEMPTY)'
select
   {[Measures].[Employees],[Measures].[Head Count],[Measures].[Terminations],[Measures].[New Hires]} on columns,
   {[employmentDate.yearMonth].[2010]:[employmentDate.yearMonth].[2012]} on rows
from [Workforce]

But, not all uses of EXISTING can be replaced by using the Count( {}, EXCLUDEEMPTY ) trick. For example:

SELECT
   { ([Measures].[Reseller Sales Amount]) } ON COLUMNS, 
   Generate({[Product].[Category].[Category].Members}, 
   TopCount( EXISTING {[Product].[Product].[Product].Members}, 
                    5, ([Measures].[Reseller Sales Amount]) ), ALL) ON ROWS 
FROM [Step-by-Step]

Or

WITH MEMBER [Measures].[Products] AS
   Count( EXISTING {[Product].[Product].[Product].Members})
MEMBER [Measures].[Reseller Products] AS 
   Count(Filter( EXISTING{[Product].[Product].[Product].Members}, ([Measures].[Reseller Sales Amount]) >= ([Measures].[Internet Sales Amount]) ) )
SELECT
   { ([Measures].[Products]), ([Measures].[Reseller Products]) } ON COLUMNS,
   { [Product].[Category].Members } ON ROWS
FROM [Step-by-Step]

chubbard avatar Jul 14 '16 13:07 chubbard

We're already on it.

https://github.com/pentaho/mondrian/pull/720

lucboudreau avatar Jul 14 '16 13:07 lucboudreau

That's great. I'm blocked with out this. When can we try it out?

chubbard avatar Jul 14 '16 13:07 chubbard

You can build it right now by cloning this pull request.. and building a jar.

lucboudreau avatar Jul 14 '16 13:07 lucboudreau

Looks like it's still an open pull request and the build failed so it looks like it is still waiting to be merged.

chubbard avatar Jul 14 '16 14:07 chubbard

Has this been ported to 4.x? Will it?

chubbard avatar Jul 22 '16 04:07 chubbard