I have created the YTD calculation based on the below link:
"http://saldeloera.wordpress.com/2013/02/07/ssas-how-to-create-dynamic-time-calculations-to-reuse-over-any-measure/?blogsub=confirming#blog_subscription-2"
The below is the result set which i can see it in excel:
Row Labels Total Bottles - WeeklyTEB Weekly-NEW QTY
CurrentMonth 3606357.755 1978514117
CurrentYear 3606357.755 1978514117
PYYTD 3606357.755 1978514117
SelectedDate 3606357.755 1978514117
YTD 3606357.755 1978514117
Unknown 3606357.755 1978514117
Grand Total 3606357.755 1978514117
Values are repeating for the measures. Where am i going wrong?
Noted in the Remarks section, the YTD function will only work for Calendar Years.
I would suggest using the PeriodsToDate function.
So if you want a Fiscal YTD:
SUM( PeriodsToDate ( [Date].[Fiscal YQMD].[Fiscal Year]
,[Date].[Fiscal YQMD].CurrentMember
)
,[Measures].[Revenue]
)
And shouldn't your measure [Measures].YEARTODATE be the measure you are trying to aggregate? I am guessing a field like [Measures].[Revenue]?
Related
I have hierarchy: Month,Monthshort and Year-Quarter-Month under TimeDim Dimension,a scope is available like below to calculate YearToDate(YTD)
Scope([TimeDim].[Year - Quarter - Month].[Month].members, [TimeDim].[Month].Members);
YTD:
([TimeDim].[YTD]=
Sum(
CrossJoin(
{[Time Calculation].[Current Period]},
PeriodsToDate([TimeDim].[Year - Quarter - Month].[Year],
[Timedim].[Year - Quarter - Month].CurrentMember
)
)
)
);
Month will be in format YYYY-MM fullname(eg: 2017-10 October) and Month short will be MMM(Oct). If I calculate YTD on the measure based on month it works fine,
How to calculate YTD based on Month Short? Do I require to create new scope to calulate YTD based on Month short? I am new to SSAS. Please help
Yes, this requires new SCOPE.
Because current scope contains Year "anchor" here: [TimeDim].[Year - Quarter - Month].[Year].
Answer will be updated once all additional questions answered
I created below scope for YTD with month short. Thus solved the problem.
Scope([Time Year Month].[Year].members,[Time Year Month].[Year - Month].[Month Short].members);
-- accumulated YTD CALCULATIONS
([Time Calculation].[YTD]=
SUM(
CrossJoin(
{[Time Calculation].[Current Period]},
PeriodsToDate([Time Year Month].[Year - Month].[Year]
)
)
)
);
End Scope;
I have spent a lot of time solving this issue, but no success yet.
I have a Date dimension called [Dim Date] and in this table I have a [Date Key] which contains all the dates from '2013-07-01' to '2016-12-31'. I also have a measure called [Retail Revenue] which is a decimal number for that date. So far so easy!
We are a retail Calendar and all our calculations/comparisons are based on a retail calendar (which is a customized table in DW).
The date hierarchy in this calendar is as below (please see the screenshot):
-- retail year (e.g. 2017)
---- retail half year (e.g. 2017-H1)
------ retail quarter year (e.g. 2017-Q1)
-------- retail month (e.g. 201702) (months from 201701 to 201712)
---------- retail week (e.g. 201708) (weeks from 201701 to 201752)
------------ date key (e.g. 2016-08-22)
SCREENSHOT
We also have an attribute called "Retail Last Year Date" which shows the equivalent date of last calendar date (e.g. 2015-08-24 in the screenshot).
I need to have a calculated member showing the "Retail Revenue" for last year (based on the attribute "Retail Last Year Date"), next to the regular "Retail Revenue" for [date key].
I tried to use ParallelPeriod and Scope, and could not get the numbers properly. Probably an easy task but I am not a hero in mdx unfortunately!
Will be more than thankful if anyone please can help me out with this.
Thanks
Rez
Hopefully this helps.
This is against AdvWrks. I've created a query scoped custom measure that gets the internet sales from the year before:
WITH
MEMBER [Measures].[Internet Sales Amount LastYear] AS
(
ParallelPeriod
(
[Date].[Calendar].[Calendar Year]
,1
,[Date].[Calendar].CurrentMember
)
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales Amount LastYear]
} ON 0
,
[Date].[Calendar].[Date].&[20070121]
:
[Date].[Calendar].[Date].&[20070127] ON 1
FROM [Adventure Works];
Here are the results:
Thanks for your response, but I didn't get how it uses the dimension property? because my calendar is customized and I cannot assume the last year calendar date is the same as this year. I have to read it from the dimension property "Retail Last Year Date").
Thanks
I am trying to put together an SQL statement that returns the SUM of a value by Year for several selected years, but on a year to date basis. In other words, running the report by selecting years I need the value for the selected years on a year to date basis. This could be something like this: By selecting the years 2015, 2014 until 2010 the Report should give 2015 value ytd of 25.02.2015, 2014 ytd of 25.02.2014 and so on.
Yet I only figured out how to select the Dates for each year to date value manually., but clearly the I was thinking. However, I was hoping to have some of this work handled with my SQL Statement using the selected years Parameter and add month and day somehow.
Has anyone ever tackled this type of problem with an SQL statement, and if so, what is the trick that I am missing?
My current sql statement for ytd data is similar to the following:
SELECT NON EMPTY { [Measures].[Sales Turnover YTD], [Measures].[Order Intake YTD] } ON COLUMNS FROM ( SELECT ( STRTOSET(#DateDate, CONSTRAINED)
This works perfectly for the one year, but still I am seeking the solution for several years.
As described above my desired result would be: after choosing several fiscal years (e.g. 2010-2015) I will get following values:
2015 Sales Turnover YTD Order Intake YTD on date today
2014 Sales Turnover YTD Order Intake YTD on date today one year ago
and so on..
Here is a script against AdvWrks that calculates the equivalent YTD totals for each of the years ON ROWS:
WITH
SET [NonEmptyDates] AS
NonEmpty([Date].[Calendar].[Date].MEMBERS)
SET [LastNonEmptyDate] AS
Tail([NonEmptyDates])
SET [SetDaysInCurrentYear] AS
Descendants
(
Exists
(
[Date].[Calendar].[Calendar Year]
,[LastNonEmptyDate].Item(0).Item(0)
).Item(0)
,[Date].[Calendar].[Date]
)
MEMBER [Measures].[NumDaysInCurrentYear] AS
Rank
(
[LastNonEmptyDate].Item(0)
,[SetDaysInCurrentYear]
)
MEMBER [Measures].[EquivYTD] AS
Aggregate
(
Head
(
Descendants
(
[Date].[Calendar].CurrentMember
,[Date].[Calendar].[Date]
)
,[Measures].[NumDaysInCurrentYear]
)
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[EquivYTD]
} ON 0
,[Date].[Calendar].[Calendar Year] ON 1
FROM [Adventure Works];
In my SSAS Cube, I have a measure called [Sales Total]. What I want to do is to create another measure that would give me the lowest sales figure in the last 6 months. I want this to be a moving minimum, calculated as the min of sales of every time period from the present month to 6 months back.
I wrote my MDX statement but it produces an error and I have hard time trying to figure out why. It is something to do with aggregating Date dimension members into a filter aggregate.
When i choose a single month member from the Date hierarchy, it returns the correct value. When I select multiple members from the hierarchy, as seen below, it errors out.
Any kind of help is appreciated.
WITH
MEMBER [Measures].[Min Sales Total Rolling 6 months] as '(MIN([Date].[Fiscal Month Hierarchy].currentmember.lag(6):[Date].[Fiscal Month Hierarchy].currentmember,[Measures].[Sales Total]))'
MEMBER [Date].[Fiscal Month Hierarchy].[FilterAggregate] as
'AGGREGATE({
[Date].[Fiscal Month Hierarchy].[Quarter].&[20141].&[201310],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20141].&[201311],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20141].&[201312],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20142].&[201401],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20142].&[201402],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20142].&[201403],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20143].&[201404],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20143].&[201405],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20143].&[201406],
[Date].[Fiscal Month Hierarchy].[Quarter].&[20144].&[201407]
})'
SELECT {
[Measures].[Min Sales Total Rolling 6 months]} ON AXIS(0)
FROM [My Cube]
WHERE ([Date].[Fiscal Month Hierarchy].[FilterAggregate])
As explained in this blog by one of the SSAS developers already many years ago, multi select does not work with CurrentMember. You should use
MEMBER [Measures].[Min Sales Total Rolling 6 months] as
MIN(Tail(EXISTING [Date].[Fiscal Month Hierarchy].[Fiscal Month Hierarchy].Members).Item(0).Item(0).lag(6)
:
Tail(EXISTING [Date].[Fiscal Month Hierarchy].[Fiscal Month Hierarchy].Members).Item(0).Item(0),
[Measures].[Sales Total])
instead.
EXISTING gets the set of all selected members. This is needed as there is no single CurrentMember. Then Tail gets the set consisting of the last of these members, Item(0).Item(0) converts that single element set to a member.
I have 2 measures:
Sales Value
Sales Value LY (calculated measure)
and a time filter with single month member and YTD formula.
If i make simple PerformancePoint report like so:
It shows up correctly like this when single month is selected from the time filter:
But when i try the YTD formula from the time filter:
the calculated measure is lost from the report.
Any ideas?
I would try to change the ParallelPeriod(Month, 12) to ParallelPeriod(Year, 1) in your measure definition:
scope ({Measures.[Sales Value LY]});
this = (PARALLELPERIOD(
[Time].[Year - Month - Date].[Year],
1,
[Time].[Year - Month - Date].CURRENTMEMBER
),
[Measures].[SALES AMOUNT]);
end scope;
ParallelPeriod only works properly if the current period is below or at the level stated as the first argument.
EDIT
Maybe changing the expression like proposed at http://sqlblog.com/blogs/mosha/archive/2007/01/13/multiselect-friendly-mdx-for-calculations-looking-at-current-coordinate.aspx would help:
scope ({Measures.[Sales Value LY]});
this = Sum(EXISTING [Time].[Year - Month - Date].[Day].Members,
(PARALLELPERIOD(
[Time].[Year - Month - Date].[Year],
1,
[Time].[Year - Month - Date].CURRENTMEMBER
),
[Measures].[SALES AMOUNT]
)
);
end scope;
I was guessing the name of your day level, maybe you have to adapt that.
Have a workaround thus:
built-in YTD semiadditive function in PPS time intelligence can be written also like this:
year.firstmonth.parent:year.month.parent
Dunno if the YTD function is buggy or whatnot, but this was the quick way to get the parallel YTD values..