Search code examples
sql-serversql-server-2008ssasmdxssas-2008

Get specific period of each year in mdx query


If I run this query

SELECT 
[Measures].[EMPLOYEE Recordable Case Rate] ON COLUMNS,
[DIM TIME].[YEAR -  QUARTER -  MONTH].[2006].[Q1]:  [DIM TIME].[YEAR -  QUARTER -  MONTH].[2010].[Q1] on ROWS

FROM
[NH_INCID]  
WHERE {[Business Component].[Region].[Novelis North America]}

It gives records starting from 2006 Q1, 2006 q2,2006 Q3, 2006 Q4------2010

Is there any way to fetch only Q1 of each year ie, of 2006,2007,2008,2009,2010 ?


Solution

  • You can use the quarter dimension attribute to filter just Q1 and put a filter on the year span you want in the where clause.

    Select {[Measures].[EMPLOYEE Recordable Case Rate]} ON COLUMNS, 
    {[DIM TIME].[YEAR - QUARTER - MONTH].[Quarter].members } on 1
    from [Model] 
    where ({ [Dim Time].[Year].[2006]:[Dim Time].[Year].[2012]}, [Dim Time].[Quarter].[Q1])
    

    You could also probably figure out a way to get the year and do something with firstchild, but my answer above seemed quicker/easier.