如何在SSAS MDX查询上的日期过滤器之间执行

时间:2016-05-11 04:48:41

标签: sql-server mdx

我有以下脚本:

WITH 
MEMBER Measures.d AS SUM
   ( { [Measures].[Opening Debit]
         , [Measures].[Transaction Debit]}
    )
MEMBER Measures.c AS SUM
   ( { [Measures].[Opening Credit]
         , [Measures].[Transaction Credit]}
    ) 
MEMBER Measures.Balance AS 
  (
  (Measures.d) - (Measures.c)
  )
SELECT    
  {Measures.Balance} ON COLUMNS,
NON EMPTY
 {(
   [Trial Balance Tree].[Accthead].[Accthead],
   [Trial Balance Tree].[Accountgroup].[Accountgroup],
   [Trial Balance Tree].[Accountgroupdet].[Accountgroupdet],
   [Trial Balance Tree].[Analysis Group].[Analysis Group],
   [Trial Balance Tree].[Account Tree ID].[Account Tree ID],
   [Trial Balance Tree].[Vchrdate].[Vchrdate],
   [Calender 1].[Thisyear].[thisyear],
 {[Trial Balance Tree].[BranchID].[BranchID].[1],
  [Trial Balance Tree].[BranchID].[BranchID].[2]}
 )}
ON ROWS
from [TrialBalance]
where
(
[Trial Balance Tree].[Date].[Date].[20140101]:[Trial Balance Tree].[Date].[Date].[20141231]
)

我想在01/01/201431/12/2014之间过滤日期。有人建议我怎么做吗?

1 个答案:

答案 0 :(得分:1)

这是一种更现代的语法:

WITH 
MEMBER [Measures].d AS 
  [Measures].[Opening Debit] +  [Measures].[Transaction Debit]
MEMBER [Measures].c AS
  [Measures].[Opening Credit] + [Measures].[Transaction Credit]
MEMBER [Measures].Balance AS 
  [Measures].d - [Measures].c
SELECT    
  [Measures].Balance ON 0,
NON EMPTY
    [Trial Balance Tree].[Accthead].[Accthead]
  * [Trial Balance Tree].[Accountgroup].[Accountgroup]
  * [Trial Balance Tree].[Accountgroupdet].[Accountgroupdet]
  * [Trial Balance Tree].[Analysis Group].[Analysis Group]
  * [Trial Balance Tree].[Account Tree ID].[Account Tree ID]
  * [Trial Balance Tree].[Vchrdate].[Vchrdate]
  * [Calender 1].[Thisyear].[thisyear]
  * {
     [Trial Balance Tree].[BranchID].[BranchID].[1],
     [Trial Balance Tree].[BranchID].[BranchID].[2]
    }
  * {
     [Trial Balance Tree].[Date].[Date].&[20140101]  
    :[Trial Balance Tree].[Date].[Date].&[20141231]
    }
ON 1
FROM [TrialBalance];

我在&[20140101][20141231]前面加上&符号,因为它们看起来像是键,而不是字幕。