Search code examples
reporting-servicesmdxssms-2012

How to add multiple filters to query?


I'm creating an SSRS report that has a texbox where you can enter a person's ID or name. I'd like to apply this as a filter to the MDX query. Applying the filter to the dataset worked, but the report takes too long to run that way.

Here's the MDX the query designer generated for me:

SELECT NON EMPTY { [Measures].[Employee Count] } ON COLUMNS
, NON EMPTY { ([Person].[Emplid].[Emplid].ALLMEMBERS 
* [Person].[First Name].[First Name].ALLMEMBERS 
* [Person].[Last Name].[Last Name].ALLMEMBERS ) } 
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM [Model]

The logic for the intended filter would be like this:

WHERE SearchParameter = [Emplid] OR [First Name] + [Last Name] like SearchParameter

I can figure out how fine tune it, I'm just looking for an example of the proper MDX syntax for the filter.


Solution

  • Thanks to Alejandro pointing me in the right direction with the FILTER function I was able to come up with a solution. I also had to learn how to use the INSTR function to compare values to the parameter.

    select  {[Measures].[Passed] , [Measures].[Did not pass]} on 0
        , filter(
            {[Person].[Emplid].Children * [Person].[First Name].Children * [Person].[Last Name].Children * [Training List].[Training Display Name].Children},
            instr([Person].[Emplid].currentmember.member_caption, @SearchParameter) > 0 
                or instr([Person].[First Name].currentmember.member_caption + ' ' + [Person].[Last Name].currentmember.member_caption, @SearchParameter) > 0) on 1
    from [Model]
    

    I hope this will help anyone facing similar issues.