简体   繁体   English

Power BI DAX 年总和

[英]Power BI DAX Sum By Year

Very new to Power BI and DAX and would appreciate a push in the right direction with this, seemingly simple, scenario, please.对 Power BI 和 DAX 非常陌生,希望通过这个看似简单的场景向正确的方向推动。 I have the following dataset:我有以下数据集:

Job Name    Quarter Year    Cost
alpha       1   2019    210
alpha       2   2019    100
alpha       3   2019    90
alpha       4   2019    28
beta        1   2020    100
kappa       1   2019    100
kappa       2   2019    90
beta        2   2020    100
beta        3   2020    75
beta        4   2020    30
kappa       3   2019    10
kappa       4   2019    30

All I am trying to do is get a measure/calculated column which calculates the total [Cost] per [Job Name] for each year.我想要做的就是获取一个度量/计算列,计算每年每个 [Job Name] 的总 [Cost]。 So for example I would get, for alpha, the value: 428. For kappa it would be: 230. Thanks!因此,例如,对于 alpha,我会得到值:428。对于 kappa,它将是:230。谢谢!

Use the below DAX to obtain the above result: New Table:使用下面的 DAX 得到上面的结果: 新表:

SUMMARIZE('Table','Table'[Job Name],"New Column",SUM('Table'[Cost]))

Using SUMMARIZE (as @Shilpa suggests) will return/add a new table to your report data source.使用 SUMMARIZE(如@Shilpa 建议的那样)将向您的报告数据源返回/添加一个新表。 I think this is not your requirement.我认为这不是您的要求。

As you are looking for a solution using a measure or a calculated column, lets know a bit details about them as they are not same with the functionality-当您正在寻找使用度量或计算列的解决方案时,请了解有关它们的一些详细信息,因为它们与功能不同-

Calculated columns:计算列:

  • Evaluated for each row in your table, immediately after you hit 'Enter' to complete the formula在您按“Enter”键完成公式后立即对表格中的每一行进行评估
  • Calculate new values from existing values for each specific rows.从每个特定行的现有值计算新值。 For example, if you have value 5 in column "A" and 4 in column "B", you can create a new Calculated column C as (A x B) which will store the result 20. This will generate results in all rows using the calculation (A x B).例如,如果“A”列中的值为 5,“B”列中的值为 4,则可以创建一个新的计算列 C 作为 (A x B),它将存储结果 20。这将在所有行中生成结果,使用计算 (A x B)。
  • Result in Calculated column saved to the model as like other column's value.计算列的结果与其他列的值一样保存到 model。

Measures:措施:

  • Evaluated when you use it in a visual and the visual is rendered在视觉对象中使用它并呈现视觉对象时进行评估
  • Measure always holds the aggregated value like - SUM, AVERAGE, COUNT. Measure 始终保存聚合值,例如 - SUM、AVERAGE、COUNT。
  • Not saved anywhere (well, actually there's a cache in the report layer but it's not part of the file when you hit Save)没有保存在任何地方(好吧,实际上在报告层中有一个缓存,但当您点击保存时它不是文件的一部分)

Now, for your scenario/requirement I think you need a simple measure as below-现在,对于您的场景/要求,我认为您需要一个简单的措施,如下所示-

total_cost = SUM('your_table'[Cost])

Your measure is ready now.你的措施现在准备好了。 Just pull column "Job Name" and measure "total_cost" to you visual.只需拉出“工作名称”列并测量“total_cost”即可。 You will get your expected output. You can use slicer to check your value in/for different dimension.您将获得预期的 output。您可以使用切片器检查不同维度的值。 Just play around:)随便玩玩:)

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

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