"GROUP BY" MDX

Post Reply
holger_b
Posts: 131
Joined: Tue May 17, 2011 10:04 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 2016
Location: Freiburg, Germany

"GROUP BY" MDX

Post by holger_b »

Probably there is actually no way of solving that by MDX, but maybe someone can think of a solution? I need a list of products and countries plus a key figure, could be revenue. The challenge is, we want to apply a benchmark to the query, like a list of products and countries where revenue "by product and country" exceeds a certain level.

Any ideas? Thanks in advance, Holger.
User avatar
Steve Rowe
Site Admin
Posts: 2422
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: "GROUP BY" MDX

Post by Steve Rowe »

You'll want to use ViewCreateByMDX, rather than the more usual subset logic.

https://www.ibm.com/docs/en/planning-an ... reatebymdx

See https://www.tm1forum.com/viewtopic.php?t=16024 for a hopefully helpful approach on creating one...
Technical Director
www.infocat.co.uk
holger_b
Posts: 131
Joined: Tue May 17, 2011 10:04 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 2016
Location: Freiburg, Germany

Re: "GROUP BY" MDX

Post by holger_b »

Brilliant, thank you, Steve! This may make me leave my good old 9.5.2 ways behind, looks really powerful... I could not find much syntax help yet, can anyone point me to something?

Regards
Holger
User avatar
Steve Rowe
Site Admin
Posts: 2422
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: "GROUP BY" MDX

Post by Steve Rowe »

MDX views are quite hard, or at least require you to step up your MDX game significantly.
I started by looking at the MDX that PA was generating for a view (there's a lot of noise in this) and then reading up on the MDX documentation, and a lot of trial and error until I got to a method that worked for me.

https://docs.microsoft.com/en-us/analys ... llversions

There's a TM1 example below, I would caveat this to say it is derived from what I see PA report as the MDX used to return a view, I've not pushed harder on this to see if there is a more concise way of writing this! I suspect I could get rid of the cross joins but never really tried.

Code: Select all

sMDX='SELECT NON EMPTY 
{[Dim5].[Hier5].[Member]} On 0,
Filter(
NONEMPTY(
	CROSSJOIN(TM1SubsetToSet([Dim1].[Hier1], "Front End - Description"),
    	CROSSJOIN(TM1SubsetToSet([Dim2].[Hier2], "Default"),
    		CROSSJOIN(TM1SubsetToSet([Dim3].[Hier3], "L0"),
			TM1SUBSETALL([Dim4])))),
    {{
    [Dim5].[Hier5].[Member]
	}}),
    [Dim5].[Hier5].[Another Member]="ABCDEF") 
    ON 1 From [Cube]';
Edit, missed the last bit off in the original post.

Not sure what release the function arrived in, it's quite possible its not available in 10.2.2. that you list yourself as being on..

A perhaps easier road for you, is to use a ruled measure to flag the intersections you are interested in and then use this to drive the next step in what you are trying to do.
Technical Director
www.infocat.co.uk
burnstripe
Regular Participant
Posts: 198
Joined: Wed May 06, 2020 2:58 pm
OLAP Product: Planning Analytics
Version: 2.0.9
Excel Version: 2016

Re: "GROUP BY" MDX

Post by burnstripe »

Following up on Steve's post you can also substitute crossjoin with * to make it a bit easier to read with fewer brackets

Code: Select all

CROSSJOIN(
        TM1SubsetToSet([Dim1].[Hier1], "Front End - Description")
       , TM1SubsetToSet([Dim2].[Hier2], "Default")
    	) 
Could be replaced by

Code: Select all

        TM1SubsetToSet([Dim1].[Hier1], "Front End - Description")
        *
       TM1SubsetToSet([Dim2].[Hier2], "Default")
If you're using an active form you could also just create your report returning everything then use TM1RPTFILTER to filter out and sort

I'd imagine the Mdx view to perform better (not tested) but it's another option
holger_b
Posts: 131
Joined: Tue May 17, 2011 10:04 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 2016
Location: Freiburg, Germany

Re: "GROUP BY" MDX

Post by holger_b »

Actually I was trying to find a way how to avoid the flags which we currently use, as setting them takes quite some performance and I would rather avoid that. Sounds to me like creating the view through MDX might do the job but I do not seem to have the time to find out how to do it exactly...

Thank you
Holger
MarenC
Regular Participant
Posts: 359
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: "GROUP BY" MDX

Post by MarenC »

Hi,

I have a question for Steve, why is there no ON 1 (rows) defined in your MDX query, and why is there no From either?

Maren
User avatar
Steve Rowe
Site Admin
Posts: 2422
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: "GROUP BY" MDX

Post by Steve Rowe »

Thanks Maren,

Because in editing the code to make it non company specific I managed to drop off the end of the statement, now updated. Thanks again
Technical Director
www.infocat.co.uk
Wim Gielis
MVP
Posts: 3128
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: "GROUP BY" MDX

Post by Wim Gielis »

Steve Rowe wrote: Tue Feb 15, 2022 10:42 am Thanks Maren,

Because in editing the code to make it non company specific I managed to drop off the end of the statement, now updated. Thanks again
Couldn’t we have some AI functionality that automatically finishes the statements just the way we want 😅
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply