OUTPUT
Negative Total Actual Total
Marketing (Expense) Advertising December Barlens Actual 24010.44 24,010.44
Marketing (Income) Discounts December Barlens Actual 43380.4 -43,380.40
Marketing (Income) Sale Promot December Barlens Actual 18.91 18.91
Marketing (Income) Sale Sponso December Barlens Actual 9181.32 -9,181.32
Marketing (Expense) TOTAL December Barlens Actual 24010.44 24,010.44
Marketing (Income) TOTAL December Barlens Actual 52542.81 -52,542.81
/* Here Marketing (Income) is being converted into + value (ie -43,380.40, -9,181.32 converted to 43380.4,9181.32) but the 18.91 value is + income so i dont want to display it. Again, The two totals Marketing(Expense) and Marketing (income) are displaying separately but i want to display them in a line so the Total should be 24010.44+ 43380.4 + 9181.32= 76572.16 */
WITH
MEMBER [Measures].[Negative Total] AS
CASE
WHEN ([Measures].[Total]) < 0 THEN [Measures].[Total]* -1 /* Actullay i want to display those marketing income has - value so condition should be like this WHEN ([Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing],[Measures].[Total]) < 0 */
THEN [Measures].[Total]* -1
ELSE [Measures].[Total]
END
MEMBER
[Dim Account].[Account Activity].TOTAL AS
[Dim Account].[Account Activity].[All]
SELECT
NON EMPTY
{[Measures].[Negative Total],[Measures].[Total]}
ON COLUMNS
,
NON EMPTY
(
{
{
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
}
*
[Dim Account].[Account Activity].[Account Activity].MEMBERS
,
{
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
}
*
[Dim Account].[Account Activity].TOTAL
}
,[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
, [Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire]
, NONEMPTY([Dim Scenario].[Scenario Name].&[Actual])
)
ON ROWS
FROM [CubeProfitLoss]
我遇到数据显示和计算问题。以下MDX显示所有正数(MEASURES.Total),如果有任何负数,则将它们转换为+值并相应显示。但是,我的要求是在层次营销我有费用和收入,我想显示所有费用,这些收入有负值,并从计算中排除正收入。所以TOTAL值将是每个交易者的所有费用+( - )收入。但目前它是单独计算我的意思,例如交易员(barlens)显示2总费用1和营销收入。 你能找到那个解决方案吗?我非常感谢你的帮助,因为过去两周我一直试图解决这个问题。
答案 0 :(得分:0)
以下MDX代码显示一行中的总营销收入显示错误结果。我认为这是因为显示的数据。现在我想显示那些只是负收入并排除正营销收入的数据。如果我能这样做会得到正确的结果
WITH
MEMBER [Measures].[Negative Total] AS
CASE
WHEN [Measures].[Total] < 0 THEN [Measures].[Total]* -1
ELSE [Measures].[Total]
END
MEMBER [Dim Account].[HierarchyMarketing].[Total Marketing Expense] AS
AGGREGATE
(
{
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
}
,
[Measures].[Negative Total]
)
MEMBER
[Dim Account].[Account Activity].TOTAL AS
[Dim Account].[Account Activity].[All]
SELECT
NON EMPTY
{[Measures].[Negative Total],[Measures].[Total]}
ON COLUMNS
,
NON EMPTY
(
{
(
{
[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].CURRENTMEMBER
)
}
,[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
, [Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire]
, NONEMPTY([Dim Scenario].[Scenario Name].&[Actual])
)
ON ROWS
FROM [CubeProfitLoss]
Wrong OUTPUT
Negative Actual
Total Total
Marketing (Expense) Advertising December Barlens Actual 24010.44 24,010.44
Marketing (Income) Discounts December Barlens Actual 43380.4 -43,380.40
Marketing (Income) Sale Promot December Barlens Actual 18.91 18.91
Marketing (Income) Sale Sponso December Barlens Actual 9181.32 -9,181.32
Total Marketing Exp All December Barlens Actual 76553 76553
Expected OUTPUT
Negative Actual
Total Total
Marketing (Expense) Advertising December Barlens Actual 24010.44 24,010.44
Marketing (Income) Discounts December Barlens Actual 43380.4 -43,380.40
Marketing (Income) Sale Sponso December Barlens Actual 9181.32 -9,181.32
Total Marketing Exp All December Barlens Actual 76572 76572
我更新了现在正确显示数据的MDX,只有问题是错误的。我认为这是因为Total Marketing Expense在添加时会获取真实数据,我甚至为此尝试了VISUALTOTALS,但仍然没有运气。
WITH
MEMBER [Measures].[Negative Total] AS
CASE
WHEN (SUM([Dim Account].[Account Marketing].&[Income]&[Marketing],[Measures].[Total])) < 0 THEN [Measures].[Total]* -1
WHEN (SUM([Dim Account].[Account Marketing].&[Income]&[Marketing],[Measures].[Total]))> 0 THEN 0
ELSE [Measures].[Total]
END
MEMBER [Dim Account].[Account Marketing].[Total Marketing Expense] AS
AGGREGATE
(
{
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[Account Marketing].&[Income]&[Marketing]
}
//, [Measures].[Negative Total]//VISUALTOTALS()
)
MEMBER
[Dim Account].[Account Activity].TOTAL AS
[Dim Account].[Account Activity].[All]
SELECT
NON EMPTY
{[Measures].[Negative Total],[Measures].[Total]}
ON COLUMNS
,
NON EMPTY
(
{
(
{
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[Account Marketing].&[Income]&[Marketing]
}
*
[Dim Account].[Account Activity].[Account Activity].MEMBERS
)
,
(
[Dim Account].[Account Marketing].[Total Marketing Expense]
,
[Dim Account].[Account Activity].CURRENTMEMBER
)
}
,[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
, [Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire]
, NONEMPTY([Dim Scenario].[Scenario Name].&[Actual])
)
//HAVING [Measures].[Negative Total] <> [Measures].[Total]
// if i execute this line, it is displaying only those data whose have different sign (i.e 43380.4, -43,380.40)
ON ROWS
FROM [CubeProfitLoss]
Wrong OUTPUT
Negative Actual
Total Total
Marketing (Expense) Advertising December Barlens Actual 24010.44 24,010.44
Marketing (Income) Discounts December Barlens Actual 43380.4 -43,380.40
Marketing (Income) Sale Promot December Barlens Actual 0 18.91
Marketing (Income) Sale Sponso December Barlens Actual 9181.32 -9,181.32
Total Marketing Exp All December Barlens Actual 28532.37 -28532.37
Expected OUTPUT
Negative Actual
Total Total
Marketing (Expense) Advertising December Barlens Actual 24010.44 24,010.44
Marketing (Income) Discounts December Barlens Actual 43380.4 -43,380.40
Marketing (Income) Sale Sponso December Barlens Actual 9181.32 -9,181.32
Total Marketing Exp All December Barlens Actual **76572** -28532.37
答案 1 :(得分:0)
您可以使用HAVING
子句
我对您的代码运行感到有些惊讶 - 看到currentmember
使用您使用它的方式有点奇怪 - 它是否有用或是否会给您带来相同的结果:
也许额外的NONEMPTY
在您使用它的方式上也是多余的?您可以将所有ON ROWS部分简化为以下内容:
WITH
MEMBER [Measures].[Negative Total] AS
CASE
WHEN (SUM([Dim Account].[Account Marketing].&[Income]&[Marketing],[Measures].[Total])) < 0 THEN [Measures].[Total]* -1
WHEN (SUM([Dim Account].[Account Marketing].&[Income]&[Marketing],[Measures].[Total]))> 0 THEN 0
ELSE [Measures].[Total]
END
,SOLVE_ORDER = 2
MEMBER [Dim Account].[Account Marketing].[All].[Total Marketing Expense] AS
AGGREGATE(
{
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
,[Dim Account].[Account Marketing].&[Income]&[Marketing]
}
)
,SOLVE_ORDER = 1
MEMBER [Dim Account].[Account Activity].TOTAL AS
[Dim Account].[Account Activity].[All]
SELECT
NON EMPTY
{[Measures].[Negative Total],[Measures].[Total]} ON 0,
NON EMPTY
{
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
,[Dim Account].[Account Marketing].&[Income]&[Marketing]
,[Dim Account].[Account Marketing].[All].[Total Marketing Expense]
}
*[Dim Account].[Account Activity].[Account Activity].MEMBERS
*[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
*[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire]
*[Dim Scenario].[Scenario Name].&[Actual]
//HAVING [Measures].[Negative Total] <> [Measures].[Total]
ON 1
FROM [CubeProfitLoss];