1
votes

What will be the DAX query to add a calculated column to power bi table which calculates sum of a column including those rows only where a certain condition is met. For eg.

If the table is as follows:

id    city       count
1      x         2
2      y         3
3      z         1
1      u         6
2      v         3

I want to add a column total count to the table and not a measure. The total count is calculated by adding counts based on same id. The expected table should be as follows:

id    city       count    totalcount
1      x         2        8       
2      y         3        6
3      z         1        1
1      u         6        8
2      v         3        6
1

1 Answers

1
votes

Try using SUMX with a FILTER:

totalcount = SUMX(FILTER(MyTable, MyTable[id] = EARLIER(MyTable[id])),[count])