Search code examples
sql-server-2008reporting-servicesssasmdx

Previous Value of Measure inside a Tuple in an MDX query


I have the following MDX query inside a report:

select 
({ [Measures].[Total]})   on columns,
non empty
[Dim1].[h1].allmembers
* [Dim1].[h2].allmembers
* [Dim1].[h3].allmembers
* [1 Date - Loss Date].[Date].[Year].allmembers
having [Measures].Total>100000 on rows
from [Monthly Summary]
where ([1 Date - Month End].[Month End Date].[Month].&[20120331])

This is selecting rows with the Total value of more than 100k in March. How would I select the rows with Total value of more than 100k either in March or February meaning get the result from the above query plus the result of this month values where the previous month is more than 100k ?

Right now, I'm doing this in two Datasets in SSRS and doing a join and lookup of one on the other and the month (the Where Clause) is read from a Report Parameter; which is close nut not correct.

Update: Weather the [Total] value in March is more than 100k or the [Total] value in February is, I need to see the March Total Value in the query result( which might be less than 100k in second scenario)


Solution

  • You can use something like this:

    SELECT ({ [Measures].[Total]}) ON COLUMNS,
    [Dim1].[h1].allmembers
    * [Dim1].[h2].allmembers
    * [Dim1].[h3].allmembers
    * [1 Date - Loss Date].[Date].[Year].allmembers
    HAVING [Measures].[Total] > 100000
    OR ([Measures].[Total], [1 Date - Month End].[Month End Date].[Month].&[20120228]) >100000 
    ON ROWS
    FROM [Monthly Summary]
    WHERE ([1 Date - Month End].[Month End Date].[Month].&[20120331])
    

    You do not need the non emtpy on the rows because null < 100000