SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


mdx tail function not working on currentmember


mdx tail function not working on currentmember

Author
Message
robinrai3
robinrai3
Mr or Mrs. 500
Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)

Group: General Forum Members
Points: 560 Visits: 367
Hi All mdx gurus,

I was checking out the tail function to achieve same the rolling 3 month sales which works using the lag function...as follows :


-- Previous 3 month sales
WITH MEMBER [Measures].[PrevThreeMonthSales] AS 'SUM( [Order Date].[CalendarHierarchy].CurrentMember : [Order Date].[CalendarHierarchy].CurrentMember.Lag(2), [Measures].[Sales Amount])'
SELECT {[Measures].[Sales Amount], PrevThreeMonthSales} ON 0,
[Order Date].[CalendarHierarchy].[Month] On 1
FROM MyFirstCube

this does not however using tail substitution:

-- Previous 3 month sales using tail
WITH MEMBER [Measures].[PrevThreeMonthSales] AS 'SUM(Tail([Order Date].[CalendarHierarchy].CurrentMember,3), [Measures].[Sales Amount])'
SELECT {[Measures].[Sales Amount], PrevThreeMonthSales} ON 0,
[Order Date].[CalendarHierarchy].[Month] On 1
FROM MyFirstCube

all i get is the same value for the current member

Question ? Can the tail function not create dynamic sets on currentmember
Mackers
Mackers
Say Hey Kid
Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)Say Hey Kid (687 reputation)

Group: General Forum Members
Points: 687 Visits: 499
You need to provide the Tail function with a set - you have provided the current member which is just one value ie a set with one value

So Tail(CurrentMember,3) = CurrentMember.

An example I use in my cubes (to get the latest year with revenue)

TAIL(NONEMPTY({[Date].[Year].Children},{[Measures].[Net Revenue]}),1);

Mack
robinrai3
robinrai3
Mr or Mrs. 500
Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)

Group: General Forum Members
Points: 560 Visits: 367
Hi Mack,

Your a diamond among the gems....fixed it...using your reply...gone back and determined the first child and created the set...and then did a tail on it....


-- Previous 3 month sales using tail
WITH MEMBER [Measures].[PrevThreeMonthSales] AS 'SUM(Tail([Order Date].[CalendarHierarchy].CurrentMember.Parent.Children(0):[Order Date].[CalendarHierarchy].CurrentMember,3), [Measures].[Sales Amount])'
SELECT {[Measures].[Sales Amount], PrevThreeMonthSales} ON 0,
[Order Date].[CalendarHierarchy].[Month] On 1
FROM MyFirstCube
robinrai3
robinrai3
Mr or Mrs. 500
Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)Mr or Mrs. 500 (560 reputation)

Group: General Forum Members
Points: 560 Visits: 367
Hi Mack ,

I'm on a roll...even simpler...using the "null" value brings back the first member of a set on the same level as the current member...only works if you use the range : (colon)


-- Previous 3 month sales using tail and "null"

WITH MEMBER [Measures].[PrevThreeMonthSales] AS 'SUM(Tail(null:[Order Date].[CalendarHierarchy].CurrentMember,3), [Measures].[Sales Amount])'
SELECT {[Measures].[Sales Amount], PrevThreeMonthSales} ON 0,
[Order Date].[CalendarHierarchy].[Month] On 1
FROM MyFirstCube


Cheers

Robin
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search