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)
)
不是說這樣可以解決問題,但最後一條語句應該是> 120。您已經在91-120語句中包含了120條。另外,@ToDOSDate的數據類型是什麼? –
@WEI_DBA謝謝? :) – mrbungle
這是一個日期時間 – mrbungle