| MDX-How can I get Last (Previous) Year to Date (YTD) values? |
| Written by Vidas Matelis | |||
| Tuesday, 01 May 2007 19:37 | |||
|
Q: How can I get Last (Previous) Year to Date (YTD) values? A: First lets clarify question. Lets say you selected date March 22, 2004. Year To Date means you are interested in the interval from January 1, 2004 up to March 22, 2004. Last (Previous) Year to date means you are interested in the intervale January 1, 2003 up to March 22, 2003. With certain exceptions, you should be able to use function ParallelPeriod to get a date in the previous year matching your selected date. Assumption here is that you have similar members in each years hierarchy. If, for example, you have just business days in day hierarchy, matching might be different. Example: Lets say you selected March 22, 2004. If we use ParallelPeriod function, we can get back member for date March 22, 2003. Query Example:
Result:
As you know how to get previous years matching day, you can calculate YTD for previous year:
Results are:
Now lets run the same query, but substitute YTD and Parallel periods with hardcoded dates. This way we will make sure that calculation is right.
Results match previous query:
Note: You can substitute YTD function with PeriodsToDate function. These tests were done on Adventure Works database.
|
Most read
- How to install Adventure Works SQL DW and Analysis Services 2005/2008 sample database and project
- MDX-How can I get Last (Previous) Year to Date (YTD) values?
- Analysis Services 2005 error: Errors in the metadata manager. The attribute with ID of ., Name of . refer
- MDX-How do you format or round KPI expression value?
- MDX-How do you calculate monthly average of one year, optionally including empty months?
Top Rated
- How to install Adventure Works SQL DW and Analysis Services 2005/2008 sample database and project
- Analysis Services 2005 XMLA script to add/drop existing partition aggregate
- Why In Reporting Services MDX query disappears after leaving "Data" tab.
- When accessing calculation tab in BIDS I am getting error Unexpected error occurred
- In an MDX query how can I get the top 3 sales years based on the order quantity?
- What TCP port SQL Server Analysis Services 2005 uses
- How to calculate YTD monthly average and compare it over several years for the same selected month
- Analysis Services 2005 error: Errors in the metadata manager. The attribute with ID of ., Name of . refer





Regards
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=83&SiteID=1
http://technet.microsoft.com/en-us/library/ms175589.aspx
Your Time dimension probably is not specified as time, and attribute for year is not specified as Year. In such case you cannot use YTD. You need to fix structure. Also, you can rewrite this using PeriodsToDate function. Just instead of dealing with attributes start working with hierarchies, that is [Date].[YourHierarchyName].[Month], etc.
I have year level like this, [Date].[Year].[Year].[All].
I tried to replace hierachy level still did not work.
Execute:
SELECT {YTD([Date].[Year].CurrentMember)} ON 0
, {[Measures].[NRT Count]} ON 1
FROM [Data Warehouse]
Do you see expected results. If no, replace YTD with PeriodsToDate and specify proper level. If PeriodsToDate works, your date dimension does not have proper "Type" property set.
WITH MEMBER [Measures].[Current YTD] AS
SUM(YTD([Date].[Year].CurrentMember), [Measures].[NRT Count])
MEMBER [Measures].[Last YTD] AS
SUM(YTD(ParallelPeriod([Date].[Year].[Year].[2007]
, 1
, [Date].[Year].CurrentMember))
, [Measures].[NRT Count]
)
SELECT {[Measures].[Current YTD]
, [Measures].[Last YTD]
} ON 0
FROM [Data Warehouse]
WHERE ([Date].[Year].[Year].[2007])