Search code examples
ssas

How can I create a KPI in SQLServer analysis services that shows a trend for the same period in the previous year


I have created a KPI and trend expression that works at the year level. If looking at total sales for a customer in 2012, the trend correctly shows whether the volume is up or down on 2011.

However, when I drill into the customer and start looking at the data at the month level, the kpi is comparing say January 2012 with the whole of 2011 where I would like it to automatically compare it with January 2011.

Here is my expression :

Iif
(
  KPIValue( "Operating Margin vs Last Year" ) >
  ( KPIValue( "Operating Margin vs Last Year" ),
    ParallelPeriod
    ( 
       [Dim Date].[Year No -  Qtr Name -  Month Name].[Year No],
       1,[Dim Date].[Year No -  Qtr Name -  Month Name].CurrentMember
    )
  ), 1, -1
)

I also tried the following, however I am pretty sure it results in always comparing with January of the current year. If looking at May 2012, I think it just subtracts 12 from 5, and floors itself at 1 (and doesn't rollback the year component of the date).

Iif
(
  KPIValue( "Operating Margin Same Month Last Year" ) >
  ( KPIValue( "Operating Margin Same Month Last Year" ),
    ParallelPeriod
    ( 
       [Dim Date].[Year No -  Qtr Name -  Month Name].[Month No],
       12,
       [Dim Date].[Year No -  Qtr Name -  Month Name].CurrentMember
    )
  ), 1, -1
)

Solution

  • I figured out why the 1st option wasn't working. In my client (Excel), I was choosing the Year/Month columns from the Date dimension and not from the date hierarchy.

    If I choose the date hierarchy it resolves correctly. I was choosing the Year/Month directly from the date dimension because I didn't want the 'Qtr Name' to be shown on this report.

    I think from now on I will not make the date dimension fields available at all, thus forcing the user (and me) to always select from the hierarchy. Secondly, I will add another hierarchy that is Year/Month only to achieve my original goal.