numeric variable in mdx query

Post Reply
bunkersoldier
Posts: 5
Joined: Thu Oct 15, 2015 12:18 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2010

numeric variable in mdx query

Post by bunkersoldier »

Hi all
This is hopefully a simple question, 'Can you use a tm1 defined numeric variable within an MDX query?'
I will show my example below;
nMin = CellGetN( cControlCube, 'HLC001', pAccount, 'HLE001' );

sCompanyMDX =
' { TOPCOUNT( { [HL Company] . [HLC001] . Children }, nMin, [ ' | cSourceCubeName | ' ] . ( [Period].[ ' | pPeriod | ' ], [Year].[ ' | pYear | ' ], [HL Account].[ ' | pAccount | ' ], [HL Measure] . [ ' | cAbs | ' ] ) ) };

The value in the cControlCube is 3
All the other variables are string in nature and if I replace nMin in the MDX query with the number 3 it all works perfectly.
I am hoping that it is just a syntax issue. I have also tried | nMin | and ' | nMin | ' neither of which worked

Thanks in advance for any help
declanr
MVP
Posts: 1831
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: numeric variable in mdx query

Post by declanr »

Your issue is that the TI code views sCompanyMDX as a string variable; it doesn't really concern itself with what it will be used for or where it has come from BUT all component of it must be entered into it as string (even if they are a number)... later when it is passed in to MDX the MDX compiler will then use the characters that individually make up your string to deduce whether each one is delimited as a string or numeric component of the overall.

e.g. NumberToString ( nMin ) will be needed; you do have a few other syntax issues with your code however (e.g. where you are placing pipes etc.)

I recommend that you keep tweaking and ASCII output the variable that you are creating; keep manually copying and pasting that output to a subset editor window until it correctly resolves and then you know it is successful.
Declan Rodger
bunkersoldier
Posts: 5
Joined: Thu Oct 15, 2015 12:18 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2010

Re: numeric variable in mdx query

Post by bunkersoldier »

Thanks declanr, all working
Post Reply