Reputation: 37
If I use the following Negative total instead of previous one i am getting the same output but still not my expected output. Is there anyone to help me out?
MEMBER [Measures].[Negative Total] AS
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 0
END
Let me explain what I am trying to achieve. I have a Dimension of [Dim Account] which has the attributes like [Account Type],[Account Activity], [Account Marketing] etc. [Account Type] is income, expense,.. [Account Activity] is like Advertising,Discounts, Sale of sponsorship,etc [Account Marketing] is the combination of those things I mean advertising is the expense whereas discounts is stored as the negative income, so ultimately discounts will be treated as marketing expense That's why my member [Negative Total] is converting the income multiplied by -1 and i want to exclude those income are positive as they are income. I want to display only those converted income and finally add up them. In my MDX, the data are displayed perfectly but added up the original value -43380.4 +18 - 9181.32= -52542.81 that was supposed to be 43380.4 +0 +9181.32= 52561.72. For comparing the original total with expected total I displayed [Measure].[Total] and [Measure].[Negative Total] concurrently. Help me please if you know the trick
WITH
MEMBER [Measures].[Negative Total] 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 0
END
SELECT
{
[Measures].[Total],[Measures].[Negative Total]} on COLUMNS
,
NON EMPTY
(
{
(
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
*
{
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
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]
Upvotes: 1
Views: 339
Reputation: 37
WOW ! I got my answers, that's the thing I was looking for. It was nothing but only changes is the display of [Negative Total Test]. I again thanks to Saurav because he gave me life of my MDX code.
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]
;
I should have asked as an another question however I have reached my question limit, sorry for that.
The above question was the part of my problem. The final output should be like my edited picture. According to Sourav's solution, he checked the condition of [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All] that worked perfectly that tiny problem but when I wanted to accumulate with original income (650,920.88) then it's coming up with big figure that's not expected. Another solution I need I want to add up marketing expense(24010.44) with negative marketing income which are already converted (43380.4+9181.32) so finally the result should be 76572.16. Please modify my MDX. Thanks a lot
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 --(2)
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]
Upvotes: 0
Reputation: 35567
(Just to add to Sourav's nice solution)
CASE
and IIF
are both slow - IIF
can be faster in some circumstances, usually it is faster choice if one of its branches can be NULL
:
MEMBER [Measures].[Negative Total Test] AS
IIF(
(
[Measures].[Total]
,[Dim Account].[Account Marketing].&[Income]&[Marketing]
) >= 0
,NULL
,[Measures].[Total] * -1
)
MEMBER [Measures].[Negative Total] AS
IIF(
[Dim Account].[Account Activity].CURRENTMEMBER
IS [Dim Account].[Account Activity].[All]
,SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
,[Measures].[Negative Total Test]
)
According to the screenshot there is no need to include Marketing in the first calc so a further simplification could be:
MEMBER [Measures].[Negative Total Test] AS
IIF(
[Measures].[Total] >= 0
,NULL
,[Measures].[Total] * -1
)
MEMBER [Measures].[Negative Total] AS
IIF(
[Dim Account].[Account Activity].CURRENTMEMBER
IS [Dim Account].[Account Activity].[All]
,SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
,[Measures].[Negative Total Test]
)
Upvotes: 1
Reputation: 5243
It is working as expected since [All]
too is a member.
To achieve what you want, add a base measure that gets the negative total and then use it in the final calculation.
MEMBER [Measures].[Negative Total Test] AS
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 0
END
MEMBER [Measures].[Negative Total] AS
CASE
WHEN [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All]
SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
ELSE [Measures].[Negative Total Test]
END
Upvotes: 2