2016-10-27 83 views
1

我想通過使用下面的邏輯設置它們來創建老化桶,儘管查詢運行的桶全部空白。我最初使用了一些使用lag的邏輯,但發現lag正在計算成員級別,而不是實際天數。我在這裏錯過了什麼?使用MDX的老化桶

WITH 


member [0-30] as (IIF (Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) >=0 AND Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) <= 30 
, [measures].[charge_amount] , 0) 
) 

member [31-60] as (IIF(Datediff('d', [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) >=31 AND Datediff('d', [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) <= 60 
,[measures].[charge_amount], 0) 
) 

member [61-90] as (IIF(Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) >=61 AND Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) <= 90 
,[measures].[charge_amount], 0) 
) 

member [91-120] as (IIF(Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) >=91 AND Datediff("d", [TXN].[Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) <= 120 
,[measures].[charge_amount], 0) 
) 

member [120+] as (IIF(Datediff("d", [TXN].Age Date], STRTOMEMBER(@ToDOSDate,CONSTRAINED)) >= 120 
,[measures].[ charge_amount], 0) 
) 
+0

不是說這樣可以解決問題,但最後一條語句應該是> 120。您已經在91-120語句中包含了120條。另外,@ToDOSDate的數據類型是什麼? –

+0

@WEI_DBA謝謝? :) – mrbungle

+0

這是一個日期時間 – mrbungle

回答

0

我會假設:

  1. 你有[TXN].[Age Date] ON ROWS,在你SELECT條款。
  2. @ToDOSDate是正確的,你已經完全測試了它在輸入到STRTOMEMBER(@ToDOSDate,CONSTRAINED)時正在工作。

Datediff是一個VBA函數,需要日期類型的數據,因爲它的參數 - 你餵養的就是類型的成員的數據。

我要做的一個進一步假設是層次結構[TXN].[Age Date]成員的Name屬性被格式化爲可以解釋爲日期。然後,您可以執行以下操作:

WITH 
    MEMBER [Measures].[0-30] AS 
     IIF (
     Datediff(
      "d" 
     ,[TXN].[Age Date].CURRENTMEMBER.NAME 
     ,STRTOMEMBER(@ToDOSDate,CONSTRAINED).NAME 
     ) >=0 
     AND 
     Datediff(
      "d" 
     ,[TXN].[Age Date].CURRENTMEMBER.NAME 
     ,STRTOMEMBER(@ToDOSDate,CONSTRAINED).NAME 
     ) <= 30 
    , [measures].[charge_amount] 
    , NULL)