I am trying to get MAT with individual attribute and a Year-Month
hierarchy. Year and Month on rows are fine (please see left of attached image) but I am unable to find a solution when Year is on columns (please see right of attached image). I tried different combination of Year-Month hierarchy and attribute hierarchy and Descendants,
Filter, etc function but none of them worked.
Thanks in advance.
It might help someone so posting the solution I have found.
It's using the existing Year > Month > Date hiearchy with a 'Month Of Year'
attribute hierarchy.
Key here is StrToMember which return member to be used for the Year > Month > Date (Hierarchy)
with
MEMBER YearName AS
RIGHT([TIME].[Year].CurrentMember.Name,4)
MEMBER MonthName AS
[TIME].[Month Of Year].CurrentMember.Name
MEMBER [Measures].[Sales Value-MAT] AS
sum(
LastPeriods(
12,
StrToMember("[TIME].[Hierarchy].[" + MonthName + " " + YearName + "]")
), [Measures].[Sales Value])
select
{[TIME].[Year].[Year].members * [Measures].[Sales Value-MAT]} on columns,
NON EMPTY { [TIME].[Month Of Year].members } ON rows
from [SalesCube]
Inspired from last post in this thread.
Related
I've build a MDX calc member that give me the year-to-date (YTD) for budget, however if the user selects multiple months, it returns the total for year. Which I believe is CurrentMember function, but how do it I get the max from the set?
Aggregate(
PeriodsToDate(
[Date].[Fiscal].[Fiscal Year]
,[Date].[Fiscal].CurrentMember
)
,[Measures].[Budget]
)
So when we have a month slicer to select the month, if the end-user selects more then 1 month, then the CurrentMember fails and the parent is used, so the Full Year (FY) is used.
It might be very late to answer this question but hopefully someone else can benefit with the answer.
for this particualr problem you have to create a dynamic set and apply scope to that. check the below MDX.
dynamic set : existing PeriodsToDate(Date].[Fiscal].[Fiscal Year],[Date].
[Fiscal].CurrentMember)
calcualted member : Aggregate( PeriodsToDate( [Date].[Fiscal].[Fiscal Year]
,[Date].[Fiscal].CurrentMember
)
,[Measures].[Budget]
)
apply scope to it scope (Date].[Fiscal].[Fiscal Year],,[Measures].[Budget])
this = aggregate (([dynamic set],],[Measures].[Budget])
end scope
this way u can select a date range without any problem
Kind Regards
mah
There are very less resources and examples pertaining this question.
Please refer to the screenshot below. It shows the dimension and measure names of my cube.
I referred to the link below for YTD and MTD calculations.
community.tableau.com/docs/DOC-5293
I have been using the following calculated member to find out MTD
Sum
(
MTD
(
StrToMember("[DIM TIME].[Date].&[" + Format(Now(),"mm/dd/yyyy") + "]")
)
,[Measures].[SALES AMOUNT]
)
It does not give me any result.
Note: This link is helpful too
community.tableau.com/message/206847#206847
Here are some screenshots
Shows the dimensions and measures I have
(The member I created)
Not an answer but an initial check I would do is the following.
Add your StrToMember to a simplified script without the calculations
SELECT
[Measures].[SALES AMOUNT] on 0,
StrToMember("[DIM TIME].[Date].&[" + Format(Now(),"mm/dd/yyyy") + "]") ON 1
FROM [YourCubeName];
Does this give a result?
I've been tasked with a rather odd Time intelligence function by my finance group that I'm trying to puzzle out.
I've been asked with creating a measure within our SSAS Cube to allow for seeing previous quarter to date based on how far we are in the current quarter. But instead of seeing a standard idea of days elapsed currently versus days elapsed previously, they would like to see days remaining versus previous days remaining.
What I mean by that is, take 1/22/2015 for example. We have 48 days remaining in our current quarter, which I have by means of a calculated measure. I need to find the corresponding working day from the previous quarter where it is also at 48 days remaining.
At that point I could create a date range with some aggregate functions off of the first date in the previous quarter to the corresponding date found in the above and come up with what they are looking for.
The best idea I've had so far is to possibly do this in the database section itself, by creating a new column that is essentially the calculated number of days remaining but stored. But at that point I'm not sure how to take a calculated measure in SSAS and filter a previous quarter date member to use that property as it were.
Do you have an utility dimensions in your cube? We have one called TimeCalculations. In there we have things such as CurrentValue, MTDValue, PrevEquivMTD, Past7Days .... I think your new logic would fit in with such a dimension.
Here is an example of PrevEquivQTD against AdvWrks that I just had a play with. Guessing this doesn't really help your scenario but I had fun writing it:
WITH
SET [NonEmptyDates] AS
NonEmpty
(
[Date].[Calendar].[Date].MEMBERS
,[Measures].[Internet Sales Amount]
)
SET [LastNonEmptyDate] AS
Tail([NonEmptyDates])
SET [CurrQ] AS
Exists
(
[Date].[Calendar].[Calendar Quarter]
,[LastNonEmptyDate].Item(0)
)
MEMBER [Measures].[pos] AS
Rank
(
[LastNonEmptyDate].Item(0)
,Descendants
(
[CurrQ]
,[Date].[Calendar].[Date]
)
)
MEMBER [Measures].[PrevEquivalentQTD] AS
Sum
(
Head
(
Descendants
(
[CurrQ].ITEM(0).PrevMember
,[Date].[Calendar].[Date]
)
,[Measures].[pos]
)
,[Measures].[Internet Sales Amount]
)
SELECT
{[Measures].[pos],[Measures].[PrevEquivalentQTD]} ON 0
,[LastNonEmptyDate] ON 1
FROM
(
SELECT
[Date].[Calendar].[Date].&[20050111]
:
[Date].[Calendar].[Date].&[20080611] ON 0
FROM [Adventure Works]
);
Your Date is 1/22/2015. You want the Same Date in Previous Quarter which would be 8/22/2015.
If this is what you want, you will have to use MDX function ParallelPeriod as shown in sample below. Please replace it with your own Dimensions and Cube.
Select
ParallelPeriod
(
[Date].[Calendar Date].[Calendar Quarter], -- Level Expression
1, -- Index
[Date].[Calendar Date].[Date].&[20150122] -- Member Expression
) On 0
From [Adventure Works]
If you want the same date in the following quarter, then replace index 1 with -1.
Cheers
I am trying to create a dynamic named set that can be used in slicing data using date dimension. I want to have a several named set something like last day, last 7 days, last month, last quarter and so on. For "last day" named set, i am thinking of doing something like.
StrToMember("[Date].[Calendar].[Day].&[" + DateAdd("d", -1,Tail( [Date].[Calendar].[Day], 1) + "]")
I want DateAdd("d", -1, Tail( [Date].[Calendar].[Day], 1) + "]") to return the member_value so that i can build the uniquename string to return a member, is it possible?
The reason why I am using DateAdd is that, sometimes I am having a gap in my data for Day level, so using previousmember will sometimes return a wrong data.
Ps: What I meant for the last day is not actually equal to function Now()-1, it is the last day that is available in the cube, that is why I cannot depend on the servers system time to achieve this.
This will hopefully give you the last day:
WITH
MEMBER [Date].[Calendar].[LastDay] AS
Tail([Date].[Calendar].[Day]).ITEM(0).ITEM(0)
SET [VariousDates] AS
{[Date].[Calendar].[LastDay]}
SELECT
[VariousDates] ON 0
FROM [MyCube]
You can then create more members in the set [VariousDates]:
WITH
MEMBER [Date].[Calendar].[LastDay] AS
Tail([Date].[Calendar].[Day]).ITEM(0).ITEM(0)
MEMBER [Date].[Calendar].[Last7Days] AS
AGGREGATE(
Tail(
[Date].[Calendar].[Day]
,7
)
)
SET [VariousDates] AS
{
[Date].[Calendar].[LastDay]
,[Date].[Calendar].[Last7Days]
}
SELECT
[VariousDates] ON 0
FROM [MyCube]
(above not tested but hopefully helps)
My MDX is fledgling at best, and it is a realistic possibility that I don't even know how to phrase my question correctly to search for an answer. Sorry if this is a duplicate.
I have a date/time hierarchy [Dates]:
[Work Date].[Dates].[Year].[Quarter].[Month].[Day]
What I want to do is return the previous 5 years worth of data, for the month of X (let's assume January):
Year Sub Total
2008 645712.11
2009 848075.43
2010 765802.60
However, I'm having trouble restricting the "Year" data, based on the specific month. I have tried this MDX code, but it yields no results at all:
SELECT [Measures].[Sub Total] ON 0,
[Work Date].[Dates].[Year] ON 1
FROM (
SELECT [Work Date].[Dates].[Month].&[01] ON 0
FROM [Data Warehouse])
If I edit the sub-select I can get a specific year, quarter and month... but I only want to restrict the month portion and not the year. I've looked into using an EXCEPT clause, but I run into the same issue. Does that make any sense? I appreciate any help, and am not opposed to reading long articles if it will further my learning / understanding. Thanks!
After your explanation in comments: To get the same child of each hierarchy level you can use the MDX function COUSIN (here the reference on msdn). As documentation said:
Returns the child member with the same relative position under a
parent member as the specified child member.
so in your case your Date dimension has to be complete without missing months or days, so you can write a query like this (I've tested on AdventureWorks)
with member [Measures].[Sub Total]
as (Cousin([Date].[Calendar].[Month].&[2004]&[1], [Date].[Calendar].CurrentMember), [Measures].[Internet Sales Amount]) , Format_string = 'Currency'
Select {[Measures].[Internet Sales Amount],[Measures].[Sub Total] } on 0
,{
[Date].[Calendar].[Calendar Year].&[2002]
,[Date].[Calendar].[Calendar Year].&[2003]
,[Date].[Calendar].[Calendar Year].&[2004]
} on 1
from [Adventure Works]
I've put side by side the total and the sub total for the years. I am considering only these 3 years because they are complete from jan to dec and I can apply cousin operator without problem.
Hope this help!