Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MDX equivalent to LIKE

Tags:

ssas

mdx

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]  
like image 463
whytheq Avatar asked Aug 21 '13 07:08

whytheq


2 Answers

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

like image 81
Marc Polizzi Avatar answered Oct 19 '22 04:10

Marc Polizzi


There is no such thing like like in plain MDX, but there is an implementation in the ASSP project: http://asstoredprocedures.codeplex.com/wikipage?title=StringFilters&referringTitle=Home

like image 23
FrankPl Avatar answered Oct 19 '22 04:10

FrankPl