问题
This seems pretty logical:
WITH
MEMBER [Date].[Date - Calendar Month].[Calendar Year].&[2013].[LastMth] AS
IIF(
Day(Now()) = 1,
TAIL([Date].[Date - Calendar Month].[Calendar Month],2).Item(1),
TAIL([Date].[Date - Calendar Month].[Calendar Month],2).Item(0)
)
SELECT
NON EMPTY
{
[Date].[Date - Calendar Month].[LastMth],
[Date].[Date - Calendar Month].[LastMth].PARENT
}
ON COLUMNS,
NON EMPTY
[Measures].[BillableIncome]
ON ROWS
FROM [ourCube]
I specify the parent of the calculated member in the first line of the script - so my member LastMth has 2013 as it's parent and sure enough the result set throws back the total for 2013 as well as the last month.
If I make it's parent 2012 in the first line:
WITH
MEMBER [Date].[Date - Calendar Month].[Calendar Year].&[2012].[LastMth] AS
IIF(
...
...
...it doesn't worry about where I get LastMth from (2013) and makes 2012 it's parent as instructed - slightly bizarre but understandable behaviour.
The following returns an empty set for the parent - I thought the parent would be [Date].[Date - Calendar Month].[(All)]? What is the parent and how can I expose it's value?
WITH
MEMBER [Date].[Date - Calendar Month].[LastMth] AS
IIF(
Day(Now()) = 1,
TAIL([Date].[Date - Calendar Month].[Calendar Month],2).Item(1),
TAIL([Date].[Date - Calendar Month].[Calendar Month],2).Item(0)
)
SELECT
NON EMPTY
{
[Date].[Date - Calendar Month].[LastMth],
[Date].[Date - Calendar Month].[LastMth].PARENT
}
ON COLUMNS,
NON EMPTY
[Measures].[BillableIncome]
ON ROWS
FROM [ourCube]
回答1:
If you do not state a parent for a calculated member, it gets a sibling of the All member, not a child of it.
As an aside: I found that most client tools - including Excel - do not expect All to have siblings, and thus if you create a calculated member in the calculation script (as opposed to just defining it in the WITH clause of a statement), do not display these, even if they are instructed to show calculated members.
来源:https://stackoverflow.com/questions/20269303/how-to-always-find-the-parent-of-a-calculated-member