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

How to retrieve month number for a fiscal month using MDX in SSAS?

我想计算 average Delivered YTD qty 在用户提供的月份期间。我如何获得会计月号。我尝试引入一个新属性 Fiscal month number 但它返回值 "All Periods" 因此在我的计算中变得无用。知道如何获得月份数字。我想避免对数据进行硬编码 :)

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];

您可以从 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];

结果: