patternsqlMinor
MDX - Getting the last 6 month Dynamically
Viewed 0 times
lastthedynamicallygettingmdxmonth
Problem
I have a Dim table that called
It is describing a User account and the dates that the account has been created.
for Example:
I would like to get the list of accounts that have been created on the last 6 month Dynamically. For example today is the 09\01\2016.
So my list of accounts will be the accounts created from the
DimAccounts. It is describing a User account and the dates that the account has been created.
for Example:
I would like to get the list of accounts that have been created on the last 6 month Dynamically. For example today is the 09\01\2016.
So my list of accounts will be the accounts created from the
01-08-2015 until 09-01-2016. Notice that this CreatedOn field does not have a hierarchy and it is an attribute of the accounts dimension .Solution
Assuming you have properly set the ValueColumn property of your CreatedOn attribute in your dimension (so that MemberValue comes back a date data type) then the following should work:
Or if you want to create a named set so that any user can just drop it on rows, put this in the calculations tab of your cube designer:
select {[Measures].[Your Measure Here]} on 0,
[DimAccounts].[AccountPK].[AccountPK].Members on 1
from [Your Cube]
where {
Filter(
[DimAccounts].[CreatedOn].[CreatedOn].Members
,[DimAccounts].[CreatedOn].CurrentMember.MemberValue > DateAdd("m",-6,Now())
)
}Or if you want to create a named set so that any user can just drop it on rows, put this in the calculations tab of your cube designer:
CREATE SET CurrentCube.[Accounts Created In Last 6 Months]
as
Exists(
[DimAccounts].[AccountPK].[AccountPK].Members,
Filter(
[DimAccounts].[CreatedOn].[CreatedOn].Members
,[DimAccounts].[CreatedOn].CurrentMember.MemberValue > DateAdd("m",-6,Now())
)
);Code Snippets
select {[Measures].[Your Measure Here]} on 0,
[DimAccounts].[AccountPK].[AccountPK].Members on 1
from [Your Cube]
where {
Filter(
[DimAccounts].[CreatedOn].[CreatedOn].Members
,[DimAccounts].[CreatedOn].CurrentMember.MemberValue > DateAdd("m",-6,Now())
)
}CREATE SET CurrentCube.[Accounts Created In Last 6 Months]
as
Exists(
[DimAccounts].[AccountPK].[AccountPK].Members,
Filter(
[DimAccounts].[CreatedOn].[CreatedOn].Members
,[DimAccounts].[CreatedOn].CurrentMember.MemberValue > DateAdd("m",-6,Now())
)
);Context
StackExchange Database Administrators Q#125732, answer score: 5
Revisions (0)
No revisions yet.