[英]How to add calculated column to a pivot table connected to SSAS tabular model?
Or in another words the question is - how to add some calculation in the pivot table based on columns which do not exist in model level.或者换句话说,问题是 - 如何根据模型级别中不存在的列在数据透视表中添加一些计算。
I've reproduced my problem using AdventureWorksDW2014 sample database.我使用AdventureWorksDW2014示例数据库重现了我的问题。
Let's say I want to calculate difference between Actual and Budget scenario amounts in the FactFinance table for each Organisation and present it in a form of pivot table.假设我想计算每个组织的FactFinance表中实际和预算方案金额之间的差异,并以数据透视表的形式呈现。
To achieve that I've created a simple model (screen above) and added SumOfAmount measure to the FactFinance table SumOfAmount:=SUM([Amount])
为了实现这一点,我创建了一个简单的模型(上面的屏幕)并将SumOfAmount度量添加到FactFinance表
SumOfAmount:=SUM([Amount])
Next, I've opened my model in Excel and created very simple pivot table (shown below)接下来,我在 Excel 中打开了我的模型并创建了非常简单的数据透视表(如下所示)
So, (the question part) now I want to add an extra column to my pivot table, which should calculate something (for example difference) between columns Actual and Budget .所以,(问题部分)现在我想在我的数据透视表中添加一个额外的列,它应该计算列Actual和Budget之间的某些东西(例如差异)。 And I want this new column been a part of the pivot table so I could filter it or\\and add new grouping levels without necessity to change something "outside" the pivot table.
我希望这个新列成为数据透视表的一部分,这样我就可以过滤它或\\并添加新的分组级别,而无需更改数据透视表“外部”的某些内容。
TRIED SO FAR到目前为止尝试过
I tried to add Calculated Field but it seems like I can only use "real" columns for calculations.我尝试添加计算字段,但似乎我只能使用“真实”列进行计算。 Columns which appeared in a pivot table based on values from COLUMNS quadrant can't be used as sources for calculations.
基于来自 COLUMNS 象限的值出现在数据透视表中的列不能用作计算源。
FINAL SOLUTION最终解决方案
I got it finally combined two pivot tables: the old one and the one with Diff
measure, defined as Diff:=[Actual Amount]-[Budget Amount]
, where我终于把它合并了两个数据透视表:旧的和带有
Diff
度量的一个,定义为Diff:=[Actual Amount]-[Budget Amount]
,其中
Actual Amount:=Calculate([SumOfAmount];'DimScenario'[ScenarioName] = "Actual")
Budget Amount:=Calculate([SumOfAmount];'DimScenario'[ScenarioName] = "Budget")
First calculated measure is good:第一个计算的度量是好的:
SumOfAmount:=SUM('FactFinance'[Amount])
Add the following Calculated measures (if needed mark as hidden):添加以下计算度量(如果需要,标记为隐藏):
Budget Amount:=Calculate([SumOfAmount],'DimScenario'[Scenariokey] = "Budget")
Actual Amount:=Calculate([SumOfAmount],'DimScenario'[Scenariokey] = "Actual")
You can use the new calculations for example in a difference calculations例如,您可以在差异计算中使用新计算
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.