2014-11-21 61 views
0

我試圖從參數化的日期檢索一個月,使用VBA函數來檢索日期參數的月份:無法通過使用MDX

vba!month(${parDate}) or 

vba!datePart(m,${parDate}) or 

vba!format(${parDate},'mmm') 

以上都不是你working.Can指導,什麼是正確的方法來做到這一點?

+0

任何一個可以告訴我做什麼我錯了? – sam140 2014-11-21 18:31:22

+1

你在哪個環境工作?什麼語言?這看起來不像MDX語句,不​​像SQL語句,就像來自任何代碼片段一樣。你能舉出一個可能包含在變量'parDate'中的示例嗎? – FrankPl 2014-11-21 19:10:43

+0

我認爲與這個問題有關,這是一個完整的答案:http://msdn.microsoft.com/en-us/library/hh510163.aspx什麼是您的片段的上下文? – whytheq 2014-11-22 02:19:55

回答

1

(嘗試大寫的「MM」,而不是「嗯」 - 即使是「毫米」是錯誤的,因爲它會尋找幾分鐘而不是幾個月)

這個問題的答案看使用日期: Changing a date format to a shorter date

MSDN是mdx中可用的vba函數的一個很好的參考,您可以使用它來玩弄日期。當前的鏈接在這裏: http://msdn.microsoft.com/en-us/library/hh510163.aspx

我假設你有一個日期維度,並且想創建一個返回數字值的計算度量值,該度量值是該月份。
使用AdWks我可以做到以下幾點:

WITH 
    MEMBER [Measures].[DateValue] AS 
    [Date].[Calendar].CurrentMember.MemberValue 
    MEMBER [Measures].[DateKey] AS 
    [Date].[Calendar].CurrentMember.Member_Key 
    MEMBER [Measures].[DateMONTH] AS 
    Mid 
    (
     [Measures].[DateKey] 
    ,5 
    ,2 
    ) 
SELECT 
    { 
    [Measures].[DateValue] 
    ,[Measures].[DateKey] 
,[Measures].[DateMONTH] 
    } ON 0 
,Order 
    (
    { 
     Exists 
     (
     [Date].[Date].MEMBERS 
     ,[Date].[Calendar Year].&[2010] 
    ) 
    } 
    ,[Date].[Calendar].CurrentMember.MemberValue 
    ,BDESC 
) ON 1 
FROM [Adventure Works]; 

但是,也許你只是想玩弄今天的日期,並提取了一個月:

WITH 
MEMBER [Measures].[DateValue] AS 
    [Date].[Calendar].CurrentMember.MemberValue 
    MEMBER [Measures].[TodayKey] AS 
    format(Now(),'yyyMMdd') 
    MEMBER [Measures].[TodayMONTH] AS 
    Mid 
    (
     [Measures].[TodayKey] 
    ,5 
    ,2 
    ) 
SELECT 
    { 
    [Measures].[DateValue] 
    ,[Measures].[TodayKey] 
,[Measures].[TodayMONTH] 
    } ON 0 
,Order 
    (
    { 
     Exists 
     (
     [Date].[Date].MEMBERS 
     ,[Date].[Calendar Year].&[2010] 
    ) 
    } 
    ,[Date].[Calendar].CurrentMember.MemberValue 
    ,BDESC 
) ON 1 
FROM [Adventure Works]; 
+0

@ whytheq:工作正常..很感謝您的快速回復 – sam140 2016-01-07 17:56:34

+0

@ sam140 ....不用擔心! – whytheq 2016-01-07 18:16:57

+0

@ whytheq:抱歉延遲迴復 – sam140 2016-01-07 18:17:53