Using the ANCESTOR function on a DATE dimension

て烟熏妆下的殇ゞ 提交于 2019-12-24 09:37:30

问题


Here is my script:

WITH MEMBER [Date].[Date - Calendar Month].[2MthPrev] AS
    (
    ANCESTOR(
        CLOSINGPERIOD([Date].[Date - Calendar Month].[Calendar Month]),
        2
    ))
SELECT  
    NON EMPTY 
    {
        [Date].[Date - Calendar Month].[2MthPrev]
    }
    ON ROWS,
    NON EMPTY
        [Measures].[Revenue]
    ON COLUMNS
FROM [OurCube] 

The query runs with no error but the result pane is empty.

I've attempted to create a custom member in the [Date - Calendar Month] hierarchy that is two months previous to the last month in the hierarchy's level [Calendar Month]. So if the last loaded month in the cube is July 2013 then I'd hope that [2MthPrev] would show the results from May 2013.

I believe the problem is with the custom member [2MthPrev] and its use of ANCESTOR - how is this fixed?


回答1:


This query returns 2 months prior from the last populated date for the given measure group. You may have to fiddle with it to make a calculated member. The second argument in tail is optional. If you don't include it, the default value is 1.

So I'm returning the item that is 2 prior to (lag) the first item (Item(0)) of the set which includes the last month (tail) from the set of months for which there are values in the Measure Group (exists clause).

select {Tail(Exists([Date].[Date - Calendar Month].[Calendar Month].members, , "Measure Group Name")).Item(0).lag(2)} on 0
 from [OurCube]



回答2:


Not sure to understand the query but assuming [Calendar Month] is having at most 2 levels (ALL + months) I guess you're asking for something like :

[a-month].parent.parent = [all].parent = null

[2MthPrev] is a scalar value and not a member; if you want to debug to sth like:

with [2MthPrev] as ancestor( ... ).uniqueName

Hope that helps.



来源:https://stackoverflow.com/questions/17489503/using-the-ancestor-function-on-a-date-dimension

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