如何在SSAS中使用MDX检索会计月份的月份数?

时间:2015-03-18 13:24:12

标签: reporting-services sql-server-2012 ssas mdx

我想计算用户提供的月数average Delivered YTD qty。我如何获得会计月份编号。我尝试引入一个新属性财务月份编号,但它返回值"所有期间"因此在我的计算中变得毫无用处。不知道如何获得月份数字。我想避免硬编码数据:)

WITH 
  MEMBER [Selected Fiscal Year] AS 
    [Date].[Fiscal Year].CurrentMember.Properties("MEMBER_KEY") 
  MEMBER [Selected Fiscal Month] AS 
    [Date].[Fiscal Month].CurrentMember.Properties("MEMBER_Value") 
  MEMBER [FM NUMBER] AS 
    [Date].[Fiscal Month Number].CurrentMember.Properties("MEMBER_Value") 
SELECT 
  {
    [Measures].[Delivered Qty]
   ,[Measures].[Delivered YTD QTY]
   ,Measures.[Selected Fiscal Month]
   ,Measures.[FM NUMBER]
  } ON COLUMNS
 ,{
      [Date].[Fiscal Month].&[Selected Fiscal Year]&[1]
    : 
      [Date].[Fiscal Month].&[2015]&[12]
  } ON ROWS
FROM [My Warehouse]
WHERE 
  [Date].[Fiscal Year].&[2015];

1 个答案:

答案 0 :(得分:0)

您可以从MEMBER_KEY属性中获取所需内容:

WITH 
  MEMBER [Measures].[k] AS 
    [Date].[Calendar].CurrentMember.Member_Key 
  MEMBER [Measures].[yearNum] AS 
    Fix([Measures].[k] / 10000) 
  MEMBER [Measures].[monthNum] AS 
    Fix(([Measures].[k] - Fix([Measures].[k] / 10000) * 10000) / 100) 
  MEMBER [Measures].[dayNum] AS 
    Fix([Measures].[k] - Fix([Measures].[k] / 100) * 100) 
  MEMBER [Measures].[backTogetherAsDate!!] AS 
    Dateserial
    (
      [Measures].[yearNum]
     ,[Measures].[monthNum]
     ,[Measures].[dayNum]
    ) 
   ,format_string = 'dd mmm yyyy' 
SELECT 
  {
    [Measures].[k]
   ,[Measures].[yearNum]
   ,[Measures].[monthNum]
   ,[Measures].[dayNum]
   ,[Measures].[backTogetherAsDate!!]
  } ON 0
 ,Tail([Date].[Calendar].[Date]) ON 1
FROM [Adventure Works];

结果如下:

enter image description here