错误的总计和IIF或案例 - MDX中的条件

时间:2016-05-24 20:22:13

标签: mdx

让我解释一下我想要实现的目标。我有[Dim Account]的维度,其具有[帐户类型],[帐户活动],[帐户营销]等属性。[帐户类型]是收入,费用,.. [帐户活动]就像广告,折扣,赞助商的销售等[账户营销]是这些事情的组合,我的意思是广告是费用,而折扣则存储为负收入,因此最终折扣将被视为营销费用这就是为什么我的会员[负面总计]正在转换收入乘以-1,我想排除那些收入是积极的,因为它们是收入。我想只显示那些转换后的收入,最后将它们加起来。在我的MDX中,数据显示完美,但是因为
而匿名添加 [Dim Account]的条件。[账户活动] .CURRENTMEMBER是[Dim Account]。[账户活动]。[全部]当我想累积原始收入(650,920.88)时,它就会出现一个不合预期的大数据。我需要的另一个解决方案我想加上营销费用(24010.44)和已经转换的负营销收入(43380.4 + 9181.32),所以最终结果应该是76572.16,就像我编辑的图片一样。请修改我的MDX。

WITH 
  //MEMBER [Measures].[Negative Total Test] AS -- (1)
  //CASE
  //    WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) < 0
  //    THEN [Measures].[Total]*-1
  //    WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) > 0
  //    THEN NULL
  //    ELSE
  //    [Measures].[Total]
  //END
  MEMBER [Measures].[Negative Total Test] AS 
    CASE 
      WHEN 
              [Dim Account].[Account Marketing].CurrentMember.Member_Caption
            = "Marketing"
          AND 
            [Dim Account].[Account Marketing].Properties("Account Type") = "Income"
        AND 
          [Measures].[Total] < 1 
      THEN 
        [Measures].[Total] * -1
      WHEN 
              [Dim Account].[Account Marketing].CurrentMember.Member_Caption
            = "Marketing"
          AND 
            [Dim Account].[Account Marketing].Properties("Account Type") = "Income"
        AND 
          [Measures].[Total] > 1 
      THEN NULL
      ELSE 
        [Measures].[Total]
    END 
  MEMBER [Measures].[Negative Total] AS 
    CASE 
      WHEN 
          [Dim Account].[Account Activity].CurrentMember
        IS 
          [Dim Account].[Account Activity].[All] 
      THEN 
        Sum
        (
          [Dim Account].[Account Activity].[Account Activity].MEMBERS
         ,[Measures].[Negative Total Test]
        )
      ELSE 
        [Measures].[Negative Total Test]
    END 
  //MEMBER [Dim Account].[Account Activity].[TOTAL] AS
  //    [Dim Account].[Account Activity].[All]
  MEMBER [Dim Account].[HierarchyMarketing].[Total Marketing Expense] AS 
    Aggregate
    (
      {
        [Dim Account].[Account Marketing].&[Income]&[Marketing]
       ,[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
      }
     ,[Measures].[Negative Total Test]
    ) 
SELECT 
  {
    [Measures].[Total]
   ,[Measures].[Negative Total]
  } ON COLUMNS
 ,NON EMPTY 
    (
      {
          [Dim Account].[HierarchyMarketing].[Account Type].&[Income]
        * 
          {VisualTotals([Dim Account].[Account Activity].[All])}
       ,
          {
            [Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
           ,[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
          }
        * 
          [Dim Account].[Account Activity].[Account Activity].MEMBERS
       ,(
          [Dim Account].[HierarchyMarketing].[Total Marketing Expense]
         ,VisualTotals([Dim Account].[Account Activity].[All])
        )
      }
     ,[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire]
     ,[Dim Scenario].[Scenario Name].&[Actual]
     ,[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
    ) ON ROWS
FROM [CubeProfitLoss];

1 个答案:

答案 0 :(得分:0)

哇!哇!我得到了答案,这就是我要找的东西。它只是改变是[负面总测试]的显示。 enter image description here

WITH
MEMBER [Measures].[Negative Total Test] AS
CASE
    WHEN
        [Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
        [Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
        [Measures].[Total]<1
    THEN [Measures].[Total]*-1

    WHEN 
        [Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
        [Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
        [Measures].[Total]>1 
    THEN NULL
	ELSE 
		[Measures].[Total]
END

MEMBER [Measures].[Negative Total] AS
CASE
	WHEN  [Dim Account].[Account Activity].CURRENTMEMBER IS  [Dim Account].[Account Activity].[All]
	THEN 
	SUM(
        [Dim Account].[Account Activity].[Account Activity].MEMBERS,
        [Measures].[Negative Total Test]
       )
   ELSE [Measures].[Negative Total Test]
END

MEMBER [Dim Account].[HierarchyMarketing].[Income] AS
	([Dim Account].[HierarchyMarketing].[Account Type].&[Income], [Measures].[Negative Total])

MEMBER [Dim Account].[HierarchyMarketing].[Total Marketing Expense] AS
 AGGREGATE
 (
 {
	[Dim Account].[Account Marketing].&[Income]&[Marketing]
	,
	[Dim Account].[Account Marketing].&[Expenses]&[Marketing] 
 }
 ,
 [Measures].[Negative Total]
 )

SELECT
 {
	//[Measures].[Total], [Measures].[Negative Total], 
	[Measures].[Negative Total Test]
 } on COLUMNS
 , 
 NON EMPTY 
 (
    {
		(
		[Dim Account].[HierarchyMarketing].[Account Type].&[Income]
		* 
		{
		[Dim Account].[Account Activity].[All]
		}	
		)
		,
        (
        {
          [Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
            ,
			[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing] 
        }
        *
        [Dim Account].[Account Activity].[Account Activity].MEMBERS 
        )
        ,
        (
        [Dim Account].[HierarchyMarketing].[Total Marketing Expense]	
	    ,
		[Dim Account].[Account Activity].[All]  
        )
     }	
	,
//	Traders,
	[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire] ,
	[Dim Scenario].[Scenario Name].&[Actual]  ,
	[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
 )
 on ROWS
FROM [CubeProfitLoss]
;