本小節內容:
Calculated Member
Named Set
本想換個非稅歷史數據庫,發現hs市非稅歷史數據庫數據是否可信是個問題:
1、是不是所有數據進系統了?
2、維度表關聯鍵是否隨時間變化,沒有配套?
換回sz縣的庫吧,起碼2017年的數據基本可信
Dimensional Calculations As Calculated Members
目前所知:
計算表單式也許可有做同樣的事情,但是,對於反覆用到的技術,可以作爲Calculated Members
he MDX specification allows three different lifetime scopes for calculated members:
- Within the duration of a query (“query scope”)
- Within the duration of a user session (“session scope”)
- Persistent within a cube until the calculated member is dropped (“global scope”)
Analysis Services supports the first two of these scopes.
基本計算成員很簡單,這裏我想比較2個項目2年的間的變化,還要比較2個項目間的變化,不是嗎,典型的交叉計算,這就有個優先級的問題,直接上個例子:
String mdxStr_10 =
"with member [Account].[v_] as" +
"'[Account].[Account_L].[政府性基金收入].[計提廉租住房資金]/[Account].[Account_L].[其他收入].[其他收入].[房租收入]'" +
" ,SOLVE_ORDER = 0" +
"member [Time].[Time].[增長] as '[Time].[Time].[2017]-[Time].[Time].[2016]',SOLVE_ORDER = 1"+
" SELECT"+
" non empty {[Account].[Account_L].[政府性基金收入].[計提廉租住房資金]," +
"[Account].[Account_L].[其他收入].[其他收入].[房租收入]," +
"[Account].[v_]} ON COLUMNS,"
+"{[Time].[Time].[2016],[Time].[Time].[2017],[Time].[Time].[增長]} ON ROWS "
+ "FROM [Col_trade_detail]";
測試結果:
由上面的結果,可知,廉租房資金2016年是房租收入的的3倍,2017年是房租收入的2倍,可見,房租收入穩定性更高。
過程中,報了個錯誤:
mondrian.parser.TokenMgrError: Encountered: "\u2018" (8216), after : ""
好像我重新修改引號就好了
Named Set:
我理解,就是Set,給set起個名字。命名set,就是爲了方便其他地方引用而已。
不多說,上例子:
String mdxStr_11 =
"with set [16-17年] as " +
"'{[Time].[Time].[2016],[Time].[Time].[2017]}' " +
" member [Account].[v_] as" +
"'[Account].[Account_L].[政府性基金收入].[計提廉租住房資金]/[Account].[Account_L].[其他收入].[其他收入].[房租收入]'" +
" ,SOLVE_ORDER = 0" +
"member [Time].[Time].[16-17增長] as '[Time].[Time].[2017]-[Time].[Time].[2016]',SOLVE_ORDER = 1"+
" SELECT"+
" non empty {[Account].[Account_L].[政府性基金收入].[計提廉租住房資金]," +
"[Account].[Account_L].[其他收入].[其他收入].[房租收入]," +
"[Account].[v_]} ON COLUMNS,"
+"{[Time].[Time].[2015],[16-17年],[Time].[Time].[16-17增長]} ON ROWS "
+ "FROM [Col_trade_detail]";
結果: