I have a Dimension [Time] on my cube. I have the following properties on my time dimension.
Date &[2015/12/25]
Month &[2015/12]
Year &[2015]
Week &[2015wk52]
Arranged into 2 hierarchies.
[Time].[Y - M - D]
Year
Month
Date
and
[Time].[Y - WK]
Year
Week
Date
I also created a measure
[Measures].[Foo YTD] AS
AGGREGATE(YTD(), [Measures].[Foo])
This seems to work great when I use the Y M D dimension in excel. But when I use the Y WK hierarchy, all my weeks return the same data.
What am I doing wrong?
My attribute relations should be correctly setup I think.
This maybe your problem.
In the definition of the YTD function: https://msdn.microsoft.com/en-us/library/ms146039.aspx
It has this remark:
the Ytd function is a shortcut function for the PeriodsToDate function
where the Type property of the attribute hierarchy on which the level
is based is set to Years.
You could prove that this is your problem by trying the PeriodsToDate option - if it then works you know that it is the attribute type that is to blame.
Related
For now sometimes I have problems with creating difficult calculated members in SSAS. Is it possible to make case which will SUM certain measure on certain level when user choose another certain level of dimension? For example we have standard time dimension with 4 levels:
Year
Month
Week
Day
Also we have some measure orders which have default function SUM in properties.
Which case do we need to calculate this: sum all orders in week which including current day which we have chosen already.
Also could you recommend me some nook or source for level up my mdx knowledge?
Thanks a lot.
Yes, it's possible, when you use MDX functions, which are connected with levels.
Here is an example with Year > Quarter > Month > Day hierarchy:
Use MDX calculated member to have a SUM of upper level member children (including selected one):
The same if you want to create calculation inside the cube:
CREATE MEMBER CURRENTCUBE.[Measures].[SameLevelMembers]
as SUM({[Report Date].[Report Date].CurrentMember.Parent.Children},[Measures].[Count]),
VISIBLE = 1 ;
And a result in cube browser:
Hundreds of articles you can find there: http://ssas-wiki.com/w/Articles#MDX
I also like this one: http://mdxpert.com because of well-structured info.
I'd like an easy way of getting the total number of days for each month in the date dimension.
Currently this information is not exposed in our cubes. Therefore I need to write custom mdx such as the following:
WITH
SET [13Mth] AS Tail([Date].[Date - Calendar Month].[Calendar Month].MEMBERS ,13)
SET [m] AS Tail([13Mth])
MEMBER [Measures].[TotalNumDaysMth] AS
Datepart
("D",
Dateadd
("M",1,
Cdate(Cstr(VBA!Month([m].Item(0).Item(0).Lag(1).Name)) + "-01-" + Cstr(VBA!Year([m].Item(0).Item(0).Lag(1).Name)))
)
- 1
)
MEMBER [Measures].[TotalNumDaysMth-1] AS
Datepart
("D",
Dateadd
("M",1,
Cdate(Cstr(VBA!Month([m].Item(0).Item(0).Lag(1).Name)) + "-01-" + Cstr(VBA!Year([m].Item(0).Item(0).Lag(1).Name)))
)
- 1
)
I don't believe our users will need this information within our cube browsing client but from a developer point of view I could do without having to always implement the above.
What approach should we use to make the above data more easily available?
I have always added an attribute to the date dimension "days in month", of type integer. You can hide this attribute, if you do not want to expose the attribute hierarchy to your users.
But you can still use in calculations.
So my advise would be add a proper attribute to your time dimension and base your calculations of on the attributes.
Hope this helps somehow.
I am assuming that in your development scenario, the month will come from Web Service/Front End/SSRS report etc. In any such cases, you can create a measure that will return the count.
Approach 1: Year-Quarter-Month-Date exists
It is a good practice to have a similar hierarchy in place. The following MDX will work:
with set CurrentMonth as
[Date].[Year-Quarter-Month-Date].currentmember
set DatesInCurrentMonth as
descendants(abc, [Date].[Year-Quarter-Month-Date].[Date])
member [Measures].countofdaysinmonth as
count(DatesInCurrentMonth)
select measures.CountOfDaysInMonth on 0
from [MyCube]
where [Date].[Year-Quarter-Month-Date].[Month].&[Feb-2004]
Approach 2: Such hierarchy doesn't exist
with set CurrentMonth as
[Date].[Month].currentmember
set DatesInCurrentMonth as
exists([Date].[Date].children, abc, "<<Any Measure group>>")
member measures.countofdaysinmonth as
count(DatesInCurrentMonth)
select measures.countofdaysinmonth on 0
from [MyCube]
where [Accident Date].[Month].&[Feb-2004]
Let me know if they work/have issues.
In my Analysis Services project operated in Microsoft Visual Studio (SQL Server BIDS), I have established an attribute named Current Date in my time dimension, which is based on a property in the DataTable. The property, created as a Named Calculation in the Data Source View, has the following Expression:
CASE WHEN Date=CONVERT(DATE,GETDATE()) THEN CONVERT(BIT,1) ELSE CONVERT(BIT,0) END
Then, the attribute has been added to the time hierarchy Date YMD, such that this has these levels: Year, Month, Day, Current Date.
Further, I have defined the following calculated member in a cube:
CREATE MEMBER CURRENTCUBE.[Measures].[Applicants 1Y lag] AS
(PARALLELPERIOD([Date].[Date YMD].[Year], 1), [Measures].[Applicants]);
It works as expected when using a date hierarchy such as Date YMD or Date YWD. However, when I use the Current Date attribute as a report filter and select True only, there is nothing. I have tried different Expressions to supplement the above member definition, but none does the trick.
(Measures.[Applicants 1Y lag], [Date].[Date YMD].[Current Date].Members) = (
Measures.[Applicants],
PARALLELPERIOD(
[Date].[Date YMD].[Year],
1,
[Date].[Date YMD].[Current Date].&[1].parent)
);
This is one of the expressions that yield nothing. What is the correct way, please? Any help would be much appreciated.
I'm having a bit of trouble accomplishing something that I think should be relatively straightforward in MDX. I would like to create a calculated member that provides a sum of one of my measures over the previous two weeks at a given point in time. My time dimension looks like:
TimeId TradingDate Day of Week
-----------------------------------
1000 11/1/2012 Thursday
1001 11/2/2012 Friday
1002 11/5/2012 Monday
1003 11/6/2012 Tuesday
... ...
What makes this particularly difficult is that my Time dimension is not quite complete. The members of my Time dimension only correspond to trading days in the stock market, and not all time. This means that weekends, holidays, or any other day in which the stock market is closed are excluded. This also means the normal methods of traversing time such as LAG or PARALLELPERIOD will not work quite right here. LAG(14), for example, means "14 trading days", which at any given point could represent a variable length of actual time.
Inside my calculated member, I'm attempting to use FILTER in order to get only time members that are within the previous two weeks of the CurrentMember. However, I can't seem to figure out the proper syntax (if there is one) to accomplish this. I imagine it would be something like:
WITH MEMBER [Sum of Price Previous 2 Weeks] AS
SUM(
FILTER(
[Time].[TimeId].Children
, [Time].[TradingDate].MemberValue
>= VBA!DATEADD("ww", -2, [Time].[TradingDate].CurrentMember.MemberValue)
)
, [Price]
)
However, this doesn't quite work. I can't seem to separate the context of the calculated members current iteration from what would be a separate context inside of the FILTER function. In other words, I'm not sure how to say:
"When iterating over the set inside of FILTER, compare the current
member of each iteration against the value of the CurrentMember in
the scope of the calculated member"
Is what I'm trying to accomplish even possible? Is there a different approach I could be taking to accomplish what I'm after?
The result you'll get from a calculated member will depend on the axis of your query. So first, make sure you have [Time].[TradingDate] in your axis.
Second, your [Time].[TradingDate] hierarchy should be ordered by Key (I assume TradingDate is the key).
Now you can use this member definition:
WITH MEMBER [Sum of Price Previous 2 Weeks] AS
SUM(
[Time].[TradingDate].CurrentMember.Lag(14):[Time].[TradingDate].CurrentMember, [Price]
)
You can use set aliases to refer to the outer CurrentMember in the Filter context:
WITH MEMBER [Sum of Price Previous 2 Weeks] AS
SUM(
GENERATE([Time].[TradingDate].CurrentMember AS CurrentDateAlias,
FILTER(
[Time].[TimeId].Children
, [Time].[TradingDate].MemberValue
>= VBA!DATEADD("ww", -2, CurrentDateAlias.Item(0).MemberValue)
)
)
, [Price]
)
GENERATE is used just to define the alias somewhere.
I'm building a report in Reporting Services 2005 based on a SSAS 2005 cube. The basic idea of the report is that they want to see sales for this fiscal year to date vs. last year sales year to date. It sounds simple, but being that this is my first "real" report based on SSAS, I'm having a hell of a time.
First, how would one calculate the current fiscal year, quarter, or month. I have a Fiscal Date Hierarchy with all that information in it, but I can't figure out how to say: "Based on today's date, find the current fiscal year, quarter, and month."
My second, but slightly smaller problem, is getting last years sales vs. this years sales. I have seen MANY examples on how to do this, but they all assume that you select the date manually. Since this is a report and will run pretty much on it's own, I need a way to insert the "current" fiscal year, quarter, and month into the PERIODSTODATE or PARALLELPERIOD functions to get what I want.
So, I'm begging for your help on this one.
You'll probably need to modify the SSRS MDX by hand to do this. It is possible to get SSAS to use "Today", it is usually done as something like this:
WITH
MEMBER [Today]
AS {
StrToMember("[Date].[Date Key].&[" + Format(now(), "yyyyMMdd") + "]")
}
SELECT
[Measures].[Some Measure]
ON COLUMNS
FROM
[Cube]
WHERE
{[Today]}
You'll need to change that to fit your own cube structure of course.
So, given that you have fiscal year, and you want to plug values in, modify the above to fit? Put together a string like I showed you that equates to the values you want to use. It sounds like you're OK after that?
You should be able to figure this out using various functions which can tell you 'where you are in the hierarchy'
e.g.
http://www.sqldev.org/sql-server-analysis-services/find-parent-of-current-day-10080.shtml
I know it is a "bit" too late but for people reaching this question page this might help:
IIF(Month(Now()) > MonthOffSetNumber, Year(Now()) + 1,Year(Now()))
This is for getting the current fiscal year. This will be applied in something like this:
SET CurrentFiscalYear AS
(
StrToSet("[Dim Date Name].[Fiscal Year].&[" + Format(IIF(Month(Now()) > MonthOffSetNumber, Year(Now()) + 1,Year(Now()))) + "]")
)
This will help for later cross join in the query.
WE find an easy way to calaculate fiscal period to date date in mdx by using parameters. Imagine that we have BeginDate (01/04/2014) and EndDate (31/03/2015). Here are the formulars. Click on Parameter "beginDate" in Report Data - right click parameters - Specify values - add expression value:
=DATEADD
("M"
,IIF(Month(Today())<4
,-Month(Today())-8
,-Month(Today())+4
)
,DATEADD("D",0-DATEPART("D",Today())+1,Today()))
Do the same for the second parameter "EndDate" and set the Defualt values - Specify values and add expression value:
=DATEADD("D",-1,DATEADD("M",12,DATEADD
("M"
,IIF(Month(Today())<4
,-Month(Today())-8
,-Month(Today())+4
)
,DATEADD("D",0-DATEPART("D",Today())+1,Today()))))
Now your ssrs report will have the fiscal period as default period.
Moise Kabongo