如果不是一個問題,創建如下立方體級成員:
CREATE
MEMBER [Measures].[Percentage of All Accounts] AS NULL;
SCOPE(
{
{ [Contract].[Unit].&[U1], [Contract].[Unit].&[U2], [Contract].[Unit].&[U3] },
[Assets Cont].[Contract Status].&[C1]
});
[Measures].[Percentage of All Accounts] =
Measures].[SUM Principal EUR]
/
SUM({[Contract].[Product Group].&[P1], [Contract].[Product Group].&[P2], [Contract].[Product Group].&[P3]}, [Measures].[SUM Principal EUR]);
END SCOPE;
另外,在查詢中使用的NonEmpty()
功能擺脫不必要crossjoins的。
SELECT
NON EMPTY
{
[Measures].[SUM Principal EUR],
[Measures].[SUM Principal USD],
[Measures].[SUM Principal Local Currency],
[Measures].[Percentage of All Accounts]
} ON COLUMNS,
NON EMPTY
NonEmpty(
[Contract].[Product Group].ALLMEMBERS,
[Dates].[YearMonth].ALLMEMBERS
) ON ROWS
FROM
(
SELECT
{ (
STRTOSET(@ContractProductGroup, CONSTRAINED),
STRTOSET(@DatesYearMonth, CONSTRAINED)
) } ON 0
FROM [Assets]
)
編輯 - WHERE子句,而不是子選擇
WITH MEMBER [Measures].[Percentage of All Accounts] AS
[Measures].[SUM Principal EUR]
/
SUM({[Contract].[Product Group].&[P1], [Contract].[Product Group].&[P2], [Contract].[Product Group].&[P3]}, [Measures].[SUM Principal EUR])
SELECT
NON EMPTY
{
[Measures].[SUM Principal EUR],
[Measures].[SUM Principal USD],
[Measures].[SUM Principal Local Currency],
[Measures].[Percentage of All Accounts]
} ON COLUMNS,
NON EMPTY
{ (
[Contract].[Product Group].ALLMEMBERS,
[Dates].[YearMonth].ALLMEMBERS
) } ON ROWS
FROM [Assets]
WHERE
{
{ [Contract].[Unit].&[U1], [Contract].[Unit].&[U2], [Contract].[Unit].&[U3] },
[Assets Cont].[Contract Status].&[C1],
STRTOSET(@ContractProductGroup, CONSTRAINED),
STRTOSET(@DatesYearMonth, CONSTRAINED)
}
EDIT 2
WITH MEMBER [Measures].[Percentage of All Accounts] AS
[Measures].[SUM Principal EUR]
/
SUM({[Contract].[Product Group].&[P1], [Contract].[Product Group].&[P2], [Contract].[Product Group].&[P3]}, [Measures].[SUM Principal EUR])
SELECT
NON EMPTY
{
[Measures].[SUM Principal EUR],
[Measures].[SUM Principal USD],
[Measures].[SUM Principal Local Currency],
[Measures].[Percentage of All Accounts]
} ON COLUMNS,
NON EMPTY
{ (
STRTOSET(@ContractProductGroup, CONSTRAINED),
STRTOSET(@DatesYearMonth, CONSTRAINED)
) } ON ROWS
FROM [Assets]
WHERE
{
{ [Contract].[Unit].&[U1], [Contract].[Unit].&[U2], [Contract].[Unit].&[U3] },
[Assets Cont].[Contract Status].&[C1]
}
謝謝您的建議。我剛剛做到了這一點,但不幸的是沒有注意到任何時間的改進。 – irusul 2015-03-31 14:20:11
@irusul - 讓我編輯我的腳本,因爲我認爲我可以看到一個問題 - 您的「ON ROWS」代碼很奇怪 - 爲什麼不直接進行正常的交叉連接? – whytheq 2015-03-31 14:52:50
這是交叉連接的另一種方式,無論如何,性能是相同的。 – irusul 2015-03-31 14:59:26