Roland
August 10, 2017, 1:51pm
1
I need an MDX query to get the last element of a dimension so that the entry in the Cube is non empty.
Imagine the Cube having the following Dimensions:
Instrument (String)
Item Index (Integer in increasing order)
Measure dimension
Now, I want the last Item Index that has non zero entries.
This is what I came up with, but it’s not working:
SELECT { [Measure Dimension].MEMBERS} ON 0 ,
Filter( {Item Index] .Members} , [Measure Dimension].[First Measure] <> "" ) ON 1
FROM [CubeName]
Where ( [Instrument].[XYZ9998] )
Thanks for any suggestion.
mwirtz
August 10, 2017, 11:32pm
2
Hi Roland,
try this for the on 1 :
{ TOPCOUNT ( FILTER ( TM1FilterByLevel ( {TM1SORT( {TM1SUBSETALL( [zSYS Item Index] )}, DESC)} , 0 ) , [Measure Dimension].[First Measure] <> "" ) , 1 ) }
If you combine that with the NON EMPTY statement at the start of the axis definition, it should give you the highest index that has an entry for [First Measure].
Cheers,
Marius
1 Like
Roland
August 14, 2017, 8:58am
3
@mwirtz Thanks Marius
I changed your suggestion a little bit, using HEAD
instead of TOPCOUNT
and removing TM1FilterByLevel
and it worked fine.
Is there any reason that TM1FilterByLevel
should be included? Maybe efficiency reasons?
My new ON 1
:
HEAD (
FILTER({TM1SORT( {TM1SUBSETALL([zSYS Item Index])}, DESC)} ,
[IR FI Ticker History Measure].[Previous Ticker] <> ''), 1) ON 1
mwirtz
August 15, 2017, 4:02am
4
Hi Roland,
I’m glad it works.
I would say HEAD is more suitable than TOPCOUNT.
TM1FilterByLevel just removes the C Elements from the set.
But I believe you don’t have any data on them anyways, so you can also just ignore them.
1 Like