简体   繁体   English

PowerPivot中计算的字段总数不正确

[英]Calculated field totals not correct in PowerPivot

I have a basic data set with a ton of slicers that roughly looks like this: 我有一个带有大量切片器的基本数据集,大致如下所示:

       Hours    SpreadPerHr      Spread
       5.00        5.00          25.00
       10.00       2.00          20.00
       8.00       10.00          80.00

Where Spread is a calculated value where Spread = Hours*SpreadPerHour. Spread是Spread = Hours * SpreadPerHour的计算值。 The problem is, the totals for these columns follow this formula too, so it looks like this: 问题是,这些列的总数也遵循这个公式,所以它看起来像这样:

       Hours    SpreadPerHr      Spread
       5.00        5.00          25.00
       10.00       2.00          20.00
       8.00       10.00          80.00
Total: 23.00      17.00         391.00

And while the hours total up just fine, SpreadPerHour is dynamic and so Spread is as well. 虽然小时总计很好,但SpreadPerHour是动态的,所以Spread也是如此。 It is incorrect to say Total Spread = Total Hours * Total SpreadPerHour. 说Total Spread = Total Hours * Total SpreadPerHour是不正确的。 Totals should be: 总计应该是:

Total: 23.00      17.00         125.00 

Is there a way I can make excel leave totals for Hours as-is, but sum the column for Spread instead of multiplying totals? 有没有办法让我可以按小时计算excel离开总数,但是将Spread列加总而不是乘以总数?

Here is what I think you have in your Power Pivot Model: 以下是我认为您在Power Pivot模型中的内容: 在此输入图像描述

You have a calculated measure for Spread, which I have labeled SpreadCalc1 . 您有一个Spread的计算度量,我将其标记为SpreadCalc1 The problem with this is that it does the aggregation before it does the multiplication. 这个问题是它在进行乘法之前进行聚合。 You need this operation to be done on a row-by-row basis and then aggregated. 您需要在逐行的基础上执行此操作,然后进行聚合。 So instead of a calculated measure, you need to create a calculated column and then sum that column. 因此,您需要创建计算列,然后对该列求和,而不是计算出的度量。

在此输入图像描述

The column I have labeled as SpreadCalc has the formula =[Hours] * [SpreadPerHr] . 我标记为SpreadCalc具有公式=[Hours] * [SpreadPerHr] The calculated measure I called Spread is just Sum([SpreadCalc]) . 我称之为Spread的计算度量就是Sum([SpreadCalc]) You can see there that the total is 125 as desired instead of 391. 你可以看到总数是125而不是391。

I know this might be a bit redundant now, but I would suggest a slightly different approach. 我知道现在这可能有点多余,但我建议采用略有不同的方法。

Adding calculated columns in "small" tables is fine, but it can cause serious performance issues with large databases. 在“小”表中添加计算列很好,但它可能会导致大型数据库出现严重的性能问题。

So to solve your problem, I believe the "correct" way is to use SUMX function. 所以为了解决你的问题,我认为“正确”的方法是使用SUMX功能。

It calculates the expression specifically for each row, which is exactly what you need. 它专门为每一行计算表达式,这正是您所需要的。 And it is smart as far as performance goes (no need to add calculated columns or perform any source-data manipulations). 就性能而言,它是智能的(无需添加计算列或执行任何源数据操作)。

If you use this formula (correct the name of the table / measures), you should get the desired results: 如果您使用此公式(更正表/度量的名称),您应该得到所需的结果:

SUMX(YourTable, [Sum Hour] * [Sum SpreadPerHr])

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM