Forum Discussion
Sum values by ID
- Anonymous7 years ago
[Column 2] = var __quantity = T[Quantity] var __sameQuantityCount = COUNTROWS ( FILTER ( T, T[Quantity] = __quantity ) ) var __sameQuantitySum = __sameQuantityCount * __quantity RETURN __sameQuantitySum
Best
Darek
Mate,
Have a look at this:
Quantity Unit Price Column2
2 £3 4
5 £7 5
2 £2 4
My code does exactly what you were asking for. It does this: Get the current Quantity (I assume it's the QuantityID you were talking about but never showed it). Then, find all the rows where Quantity is the same as the current one and count the number of rows with it. Then multiply the Quantity by the number of rows and return the number. This is exactly what you wanted the code to do. Is it not?
You should be maximally clear about your requirements, otherwise you'll get what people think you wanted.
Best
Darek
Hi!
Actually...it does, but instead of counting I need sum, so I changed a little your code and it works perfect!
Michal
- Anonymous7 years agoNot applicable
Well, I'm happy it works for you but the logic in your formula is exactly the same as mine as much as I'm able to say. What's worse, your formula is slower than mine. You should almost NEVER put a whole table as a filter in CALCULATE. This slows calculation down big time and if you do this in regular measures, sometimes you'll be scratching your head not knowing why the formula returns seemingly nonsensical results.
Best
Darek