汇总基于多个维度成员的值以通过SCOPE语句创建损益报告

时间:2019-05-27 09:03:33

标签: ssas mdx

我对SSAS MDX相对较新,并且正面临在不同维度成员的所有度量上创建聚合的问题。 下图最好地描述了我要实现的目标: Problem and What the solution should be

这是草案,是更复杂场景的简化,因此,请不要打扰;-)。 经过一系列实验,我发现可以使用一个简单的维度而不与其他维度建立联系,从而能够使用SCOPE语句覆盖报告中产生的结果。 简单维“ Kurz PuL”包含前面的成员(Umsatz .. Periodenergebnis),并应生成“利润+损失”报告。

Kurz PuL Dimension

当前有效的方法是显示单个成员(例如Umsatz,Wareneinsatz,SbA,Personal)的结果。 但是我不能汇总一个成员以上的值来获得一个汇总,例如:Umsatz + Wareneinsatz = Rohertrag。我尝试了不同的方法,但没有任何效果。 请参阅以下SCOPE语句,这些语句用于“替代” Excel中显示的结果值(第一个图像^^):

SCOPE语句:

    /*
The CALCULATE command controls the aggregation of leaf cells in the cube.
If the CALCULATE command is deleted or modified, the data within the cube is affected.
You should edit this command only if you manually specify how the cube is aggregated.
*/
CALCULATE;

SCOPE ([Kurz PuL].[Calculated].[Umsatz]);
    THIS = AGGREGATE([EinfacheBwaZeile].[Hierarchy].&[U]);
END SCOPE;

SCOPE ([Kurz PuL].[Calculated].[Wareneinsatz]);
    THIS = AGGREGATE([EinfacheBwaZeile].[Hierarchy].&[W]);
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Rohertrag]);
    THIS = AGGREGATE(FILTER([EinfacheBwaZeile].[Hierarchy].CurrentMember, { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W] }));
END SCOPE;

SCOPE ([Kurz PuL].[Calculated].[Personal]);
    THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[P] });
END SCOPE;

SCOPE ([Kurz PuL].[Calculated].[Marketing]);
    THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[M] });
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Deckungsbeitrag]);
    THIS = AGGREGATE( {   [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
                        , [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D] });
END SCOPE;

SCOPE ([Kurz PuL].[Calculated].[SbA]);
    THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[S] });
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBITDA]);
    THIS = AGGREGATE( {   [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
                        , [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
                        , [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A] });
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBIT]);
    THIS = AGGREGATE( {   [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
                        , [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
                        , [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
                        , [EinfacheBwaZeile].[Hierarchy].&[I] });
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBT]);
    THIS = AGGREGATE( {   [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
                        , [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
                        , [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
                        , [EinfacheBwaZeile].[Hierarchy].&[I]
                        , [EinfacheBwaZeile].[Hierarchy].&[T] });
END SCOPE;

/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Periodenergebnis]);
    THIS = AGGREGATE( {   [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
                        , [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
                        , [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
                        , [EinfacheBwaZeile].[Hierarchy].&[I]
                        , [EinfacheBwaZeile].[Hierarchy].&[T]
                        , [EinfacheBwaZeile].[Hierarchy].&[E] });
END SCOPE;

我一直在寻找一种资源,该资源解释如何在多个成员上进行聚合,但是没有找到解决方案。 如何使用AGGREGATE()函数合并/求和与[EinfacheBwaZeile]的多个维度成员相关的值。[层次结构] .A,...,。B,.... C?

非常感谢您的回答! 提前致谢, 柯特

-更新2019-05-28作为Moaz于2019-05-27的答复:- 嗨Moaz, 谢谢你的建议。 可悲的是,该解决方案无法满足我的需求。 首先要注意的是,我需要一个SCOPE语句,而不是SELECT-MDX。 其次,我需要“概括”另一维度的特定成员的所有度量。乍一看,它看起来像“运行总计”,但这取决于“上一个”成员的值,其中一些成员可能会被跳过。 用Adventure Works示例的话,下面显示了我所需要的:

SCOPE (MountainBikeSales);
    THIS = AGGREGATE(Product.&[Bikes]);
END SCOPE;
SCOPE (BikesAndAccessories);
    THIS = AGGREGATE({ Product.&[Bikes], Product.&[Accessories] });
END SCOPE;
SCOPE (BikesAccsClothing);
    THIS = AGGREGATE({ Product.&[Bikes], Product.&[Accessories], Product.&[Clothing] });
END SCOPE;

更清楚吗? 您甚至可以想到通过汇总自行车和服装而不是附件来跳过附件的SCOPE。 我的问题是,第一个语句会成功(该语句总结了一个成员),而其他语句则不会。

谢谢您的建议! 柯特

1 个答案:

答案 0 :(得分:0)

我不确定我是否完全了解您的问题。但是我想您想知道如何计算跑步总数。就是这种情况,请看下面的示例

with 
member 
[Measures].[Internet Sales AmountRunningtotal]
as 
case when [Measures].[Internet Sales Amount] = null then null 
else 
sum({[Product].[Subcategory].firstchild:[Product].[Subcategory].currentmember},[Measures].[Internet Sales Amount])
end
select {[Measures].[Internet Sales Amount],
[Measures].[Internet Sales AmountRunningtotal]
} on columns,

non empty
([Date].[Calendar Year].[Calendar Year],[Date].[Calendar Quarter of Year].[Calendar Quarter of Year],
[Product].[Category].[Category],[Product].[Subcategory].[Subcategory])
on 
rows 
from 
[Adventure Works]

结果enter image description here