How to calculate the total of a column in a table

随声附和 提交于 2019-12-11 07:33:21

问题


In my table below, I've got the measure "Valor Total" as:

Valor total = SUM('Códigos e valores'[Valor unitário])*SUM(Csv[Quant.])

This works ok for all the rows of the table except for the grand total at the bottom, because the definition can't be quantity * price.

The problem here is that the field "Quant" is on a table with many-to-one relationship with another table (Table2).

This Table2 has a relationship of one-to-many to table "Códigos e valores" where field "Valor Unitário" is located.

Therefore, SUMX doesn't work in this scenario, not even with a RELATED in the expression.

But how to express this in the correct way?


回答1:


Assuming your two tables are related by some kind of ID column, you should be able to do something like this:

Valor total = SUMX(
                  SUMMARIZE('Códigos e valores',
                      'Códigos e valores'[ID],
                      "Quantity", SUM(Csv[Quant.]),
                      "Value", SUM('Códigos e valores'[Valor unitário])),
                  [Quantity] * [Value])

Maybe a better way to do this would be to create a measure using the Csv table instead:

TotalValue = SUMX(Csv, Csv[Quant.] * RELATED('Códigos e valores'[Valor unitário]))


来源:https://stackoverflow.com/questions/50068673/how-to-calculate-the-total-of-a-column-in-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!