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
[Column 2] = var __quantity = T[Quantity] var __sameQuantityCount = COUNTROWS ( FILTER ( T, T[Quantity] = __quantity ) ) var __sameQuantitySum = __sameQuantityCount * __quantity RETURN __sameQuantitySum
Best
Darek
- Anonymous7 years agoNot applicable
Thx Darek for quick answer, but I don't think this is what I was asking for.
What if I've let say 10000 rows with Quantity:
1
2
3
3
2
1
and so on...and I want to sum the quantity by each row. Not doing count though.
Cheers!
Michal
- Anonymous7 years agoNot applicable
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
- Anonymous7 years agoNot applicable
Hi!
Actually...it does, but instead of counting I need sum, so I changed a little your code and it works perfect!
Column 3 =var __quantity = 'Table from records'[Quantity]var __sameQuantityCount =CALCULATE(SUM('Table from records'[Quantity]),FILTER ('Table from records','Table from records'[Quantity] = __quantity))RETURN__sameQuantityCountThx for help :)My apologies if I was not clear about what I need :)Cheers!
Michal