[英]MDX Efficiency, measures from the same Hierarchy
我在VBA
/ SQL
相當先進。
我正在研究Excel中SSAS
多維數據集的摘錄以替換數據透視表。 我沒有訪問SQL server
或SSMS
權限。 我是第一次使用MDX
直接從多維數據集中提取此信息。
這樣做的大部分原因是要刪除手動多維數據集樞軸表更新,在該更新中,由於個人過度設置了樞軸表和/或未向下擴展其他公式以使其匹配而出現問題。
我產生了一個對我strMdx
的查詢,下面提供了該查詢(在VBA
加載到strMdx
字符串中):
strMDX = "WITH MEMBER [Measures].[Sector] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sector]).NAME "
strMDX = strMDX & "MEMBER [Measures].[Industry] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Industry]).NAME "
strMDX = strMDX & "MEMBER [Measures].[Sub Industry] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sub Industry]).NAME "
strMDX = strMDX & "MEMBER [Measures].[Account] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Account]).NAME "
strMDX = strMDX & "MEMBER [Measures].[Sub Account] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sub Account]).NAME "
strMDX = strMDX & "MEMBER [Measures].[Level] as ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Level]).NAME "
strMDX = strMDX & "SELECT NON EMPTY ( {[Measures].[Sector], [Measures].[Industry], [Measures].[Sub Industry], [Measures].[Account], [Measures].[Sub Account], [Measures].[Level], "
strMDX = strMDX & "[Measures].[iCounts] }) ON 0, "
strMDX = strMDX & "NON EMPTY( [Date].[DayYear].[Year],[Date].[MonthYear].[MonthName]) ON 1, "
strMDX = strMDX & "NON EMPTY( DESCENDANTS([Sector].[IndH],,LEAVES)) HAVING [Measures].[iCounts] >0 ON 2 FROM ( SELECT ( "
strMDX = strMDX & "[Date].[MonthYear].[Date].&[" & Format(strStartDte, "yyyymmdd") & "]&[" & Format(strStartDte, "dd mmm yyyy") & "] : "
strMDX = strMDX & "[Date].[MonthYear].[Date].&[" & Format(strEndDte, "yyyymmdd") & "]&[" & Format(strEndDte, "dd mmm yyyy") & "] ) "
strMDX = strMDX & "ON 0 FROM [IndustryCube])"
這是MDX
:
WITH
MEMBER [MeASures].[Sector] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sector]).NAME
MEMBER [MeASures].[Industry] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Industry]).NAME
MEMBER [MeASures].[Sub Industry] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sub Industry]).NAME
MEMBER [MeASures].[Account] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Account]).NAME
MEMBER [MeASures].[Sub Account] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Sub Account]).NAME
MEMBER [MeASures].[Level] AS
ANCESTOR([Sector].[IndH].CURRENTMEMBER,[Sector].[IndH].[Level]).NAME
SELECT
NON EMPTY
(
{ [MeASures].[Sector]
, [MeASures].[Industry]
, [MeASures].[Sub Industry]
, [MeASures].[Account]
, [MeASures].[Sub Account]
, [MeASures].[Level],
[MeASures].[iCounts] }
) ON 0,
NON EMPTY
(
[Date].[DayYear].[Year]
,[Date].[MonthYear].[MonthName]) ON 1,
NON EMPTY
(DESCENDANTS([Sector].[IndH],,LEAVES))
HAVING [MeASures].[iCounts] > 0 ON 2
FROM (
SELECT (
[Date].[MonthYear].[Date].&[ & Format(strStartDte, yyyymmdd) ]&[ & Format(strStartDte, dd mmm yyyy) ] :
[Date].[MonthYear].[Date].&[ & Format(strEndDte, yyyymmdd) ]&[ & Format(strEndDte, dd mmm yyyy) ] )
ON 0
FROM [IndustryCube]
)
此查詢需要注意兩個關鍵方面:
[Sector].[IndH]
)中拆分並使用多個級別,因此我需要展平層次結構。 我通過使用后代來完成此任務,然后將每個級別定義為自己的度量。 這確實可以拉平層次結構,但我認為這是一種解決方法。 除了以上兩點,我認為這是一個非常標准的MDX
語句。
我遇到的關鍵問題是,如果我說運行一兩個月,則查詢運行得很好,盡管只需要一分鍾多的時間。 如果我運行了5年以上(我需要這樣做),那么它將花費大量時間,而我從來沒有使它成功運行。
從性能的角度來看,我可以對此查詢做些什么來改善它?
我懷疑問題與扁平化層次有關。 不幸的是,無法解決此問題,因為多維數據集尚未在層次結構或包含我可以從中提取的字段的另一個層次結構中設置單獨的維度。
我很想將它移到您的vba
內的幾個mdx
腳本中,以嘗試使事情更具可讀性。
我猜想在vba
您正在遍歷第三軸中的成員。 如果是這樣,請從大腳本中刪除該腳本,並創建一個返回這些成員的小mdx腳本。 可能像:
SELECT
NON EMPTY
[MeASures].[iCounts] ON 0,
NON EMPTY
DESCENDANTS([Sector].[IndH],,LEAVES) ON 1
FROM (
SELECT (
[Date].[MonthYear].[Date].&[ & Format(strStartDte, yyyymmdd) ]&[ & Format(strStartDte, dd mmm yyyy) ] :
[Date].[MonthYear].[Date].&[ & Format(strEndDte, yyyymmdd) ]&[ & Format(strEndDte, dd mmm yyyy) ] )
ON 0
FROM [IndustryCube]
)
外循環可以遍歷從上面返回的成員,並將每個成員饋入以下內容:
SELECT
NON EMPTY
[MeASures].[iCounts] ON 0,
NON EMPTY
[Date].[DayYear].[Year]
*[Date].[MonthYear].[MonthName]
*[Sector].[IndH].[Sector]
*[Sector].[IndH].[Industry]
*[Sector].[IndH].[Sub Industry]
*[Sector].[IndH].[Account]
*[Sector].[IndH].[Sub Account]
*[Sector].[IndH].[Level] ON 1
FROM
(
SELECT
[Date].[MonthYear].[Date].&[ & Format(strStartDte, yyyymmdd) ]&[ & Format(strStartDte, dd mmm yyyy) ] :
[Date].[MonthYear].[Date].&[ & Format(strEndDte, yyyymmdd) ]&[ & Format(strEndDte, dd mmm yyyy) ]
ON 0,
[Sector].[IndH].&[ ....strFromOuterLoopHere... ON 1
FROM [IndustryCube]
);
大括號(..)
是在使用mdx
時要警惕的一件事-這表明處理器要創建一個元組。 您問題中的腳本有很多額外的花括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.