Move back x members in same hierarchy

删除回忆录丶 提交于 2019-12-11 13:08:02

问题


Is there a function which moves back a set number of members in a specified hierarchy's level?

It would be something like the following if I want to move back two members:

SOMEFUNCTION([someMember], [specifiedLevel],-2)

So an example would be:

WITH MEMBER [Date].[Date - Calendar Month].[2MthPrev] AS
    SOMEFUNCTION(
    CLOSINGPERIOD([Date].[Date - Calendar Month].[Calendar Month]),
    [Date].[Date - Calendar Month].[Calendar Month],
    -2
    )

回答1:


There are a few different functions that you could try out:

Lag: Returns the member that is a specified number of positions before a specified member at the member's level.

Example: this will return December 2001

SELECT [Date].[Fiscal].[Month].[February 2002].Lag(2) ON 0
FROM [Adventure Works]

See http://technet.microsoft.com/en-us/library/ms144866.aspx for more details

ParallelPeriod: Returns a member from a prior period in the same relative position as a specified member.

Example:

SELECT ParallelPeriod ([Date].[Calendar].[Calendar Quarter], 3, 
       [Date].[Calendar].[Month].[October 2003]) ON 0
FROM [Adventure Works]

See http://technet.microsoft.com/en-us/library/ms145500.aspx for more details

(Examples are taken from the technet site)



来源:https://stackoverflow.com/questions/17489100/move-back-x-members-in-same-hierarchy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!