简体   繁体   中英

MDX YTD returning null

I'm new to MDX and i was trying to use the YTD function on my cube but I'm getting a problem with it.

If I specify the date in the code it works fine:

    WITH MEMBER [Time].[Year -  Quarter -  Month -  Date].[YTD_SALES] AS
    Aggregate(
        YTD([Time].[Year -  Quarter -  Month -  Date].[August 2014])
    )
SELECT 
    [Time].[Year -  Quarter -  Month -  Date].[YTD_SALES] ON COLUMNS,
    [Item].[Item].Children ON ROWS
FROM
    [TBA_SALES]
WHERE
    [Measures].[Sales LCY]

but if I replace [March 2014] with CurrentMember the results come back all null.

Appreciate any help.

Do you have your Time dimension set as time type?

Another thing what you can try is to see what are you getting as current member. To try this add:

MEMBER YTDStr AS MEMBERTOSTR([Time].[Year -  Quarter -  Month -  Date].CurrentMember)

then add it to query as you would do for measure:

...
SELECT 
    { [Time].[Year -  Quarter -  Month -  Date].[YTD_SALES], YTDStr } ON COLUMNS,
...

EDIT: You are getting [Time].[Year - Quarter - Month - Date].[All] which is top member in hierarchy. Therefore it is not possible to return YTD for all member.

In order to fix this issue you need to add a time dimension member on rows:

  WITH MEMBER [Time].[Year -  Quarter -  Month -  Date].[YTD_SALES] AS
    Aggregate(
        YTD([Time].[Year -  Quarter -  Month -  Date].[August 2014])
    )
SELECT 
    [Time].[Year -  Quarter -  Month -  Date].[YTD_SALES] ON COLUMNS,
    {[Item].[Item].Children, [Time].[Year -  Quarter -  Month -  Date].ALLMEMBERS} ON ROWS
FROM
    [TBA_SALES]
WHERE
    [Measures].[Sales LCY]

I am not sure what you are after in this query, so it's kind of difficult to point you in right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM