问题
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