x

Moving Totals in SSAS

This is how I am creating my moving totals as columns in my cube:

MATTY (Moving Annual Total This Year)

SUM ( { [Time Period].[Month].CURRENTMEMBER.Lag(12) : [Time Period].[Month].CURRENTMEMBER }, [Measures].[MeasureColumnName])

MATLY (Moving Annual Total Last Year)

SUM ( { [Time Period].[Month].CURRENTMEMBER.Lag(24) : [Time Period].[Month].CURRENTMEMBER.Lag(12) }, [Measures].[MeasureColumnName])

How do I do the following?

YTDTY (Year To Date This Year)

YTDLY (Year To Date Last Year - up to same date as today)

more ▼

asked Oct 27 '09 at 03:38 PM in Default

Raj More gravatar image

Raj More
1.7k 77 82 84

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

There is a YTD function in MDX, which is very useful. However, it only works on hierarchies in a dimension marked as Time that have an attribute which is marked as the type 'Year'. It doesn't work on Financial Year, etc. So PeriodsToDate is often better.

In YTDLT, I'm telling it to take a Year ago in the Calendar hierarchy. In YTDTY, I'm just looking at the periods to date until the CurrentMember (which is default in the PeriodsToDate function).

Try:

YTDTY AS SUM(PeriodsToDate([Time Period].[Calendar].[Year]),[Measures].[MeasureColumnName])YTDLY AS SUM(PeriodsToDate([Time Period].[Calendar].[Year], ParallelPeriod([Time Period].[Calendar].[Year])),[Measures].[MeasureColumnName]) 
more ▼

answered Oct 27 '09 at 08:40 PM

Rob Farley gravatar image

Rob Farley
5.7k 15 18 20

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x166
x24
x17

asked: Oct 27 '09 at 03:38 PM

Seen: 1971 times

Last Updated: Oct 27 '09 at 03:38 PM