Page 1 of 1

MDX - FilterByPattern on Attributes

Posted: Thu Jul 26, 2018 1:00 pm
by garry cook
Someone asked me today how to pull a wildcard search against an attribute in MDX. I must be getting rusty (I blame Tableau and PowerBI) as this turned out to be a bit more long winded than I thought and I ended up sticking at the following rather obtuse statement - in this case returning Employees which have *PR* in their Cost Centre attribute.

{ FILTER(
{ TM1FILTERBYLEVEL(
{ TM1SUBSETALL( [Employee] ) }, 0) }
, INSTR([Employee].[Cost Centre], "PR") >0
)}

Seems messier than it should be - any tidy up suggestions welcome!

KR

Re: MDX - FilterByPattern on Attributes

Posted: Thu Jul 26, 2018 7:28 pm
by Wim Gielis
That's about the shortest you can have, IMO. Except the fact that { } are often not needed in MDX statements.
I wouldn't call it messy.

Re: MDX - FilterByPattern on Attributes

Posted: Fri Jul 27, 2018 6:48 am
by garry cook
Fair enough - thanks for the conf Wim, much appreciated.

KR

PS I like to keep the { }'s for the sake of my own sanity when checking the syntax!

Re: MDX - FilterByPattern on Attributes

Posted: Fri Jul 27, 2018 7:54 am
by Wim Gielis
garry cook wrote: Fri Jul 27, 2018 6:48 amPS I like to keep the { }'s for the sake of my own sanity when checking the syntax!
I like to keep them out.

We have ( ) [ ] so an overdose of { } is just too much !

Also, Notepad++ does not recognize { } correctly in the syntax highlighting if } exists for control objects.
This breaks down my syntax checking and therefore for my own sanity I keep them out as much as needed and possible.