MDX equivalent to LIKE

whytheq picture whytheq · Aug 21, 2013 · Viewed 10.5k times · Source

In SQL I like to search a column for matches of a particular string using something like this:

SELECT t.attributeNAME
FROM myTable t
WHERE t.attributeNAME LIKE '%searchString%'

I might like to use that in a temp table and then use the result in subsequent sections of a longer script like so:

--find the keys
SELECT t.attributeKEY
INTO #Temp
FROM myTable t
WHERE t.attributeNAMELIKE '%searchString%'

--use the keys
SELECT SUM(f.measure)
FROM myFacts f
   INNER JOIN #Temp t ON
    f.attributeKEY = t.attributeKEY

--use the keys again
SELECT SUM(F.measure)
FROM myOtherFacts F
   INNER JOIN #Temp t ON
    F.attributeKEY = t.attributeKEY

Is there an equivalent to this in MDX? If I have an idea what items from a hierarchy that I'm after can I somehow use a searchString to filter to a specific set of items?


EDIT

As pointed out by Marc Polizzi answer it seems like instr is very useful in this situation and I can do the following:

CREATE SET [xCube].[Set_Names] AS
    {FILTER(
    [xDimension].[xHierarchy].[xLevel].Members,
    (InStr(1, [xDimension].[xHierarchy].CurrentMember.NAME, "WIL") <> 0) 
        )
        }

GO

SELECT  
    NON EMPTY 
           [Set_Names]
    ON ROWS,
    NON EMPTY
           [Measures].[x] 
    ON COLUMNS
FROM [xCube]  

GO

SELECT  
    NON EMPTY 
           [Set_Names]
    ON ROWS,
    NON EMPTY
           [Measures].[y] 
    ON COLUMNS
FROM [xCube]  

GO

SELECT  
     NON EMPTY 
           [Set_Names]
     ON ROWS,
     NON EMPTY
           [Measures].[z] 
     ON COLUMNS
FROM [xCube]  

Answer

Marc Polizzi picture Marc Polizzi · Aug 21, 2013

You might be able to use the Instr function even if it does not support wildcard.