Please help me to get Grouped Sum of a column based on a value from another column:
Example:
I have 3 first columns: I need to get 4th column reflecting the sum of the2st column based on the value of 3rd column
Description | Amount | Account | SumColumn |
1001 | 150 | 1001 | 600 |
1001 | 200 | 1003 | |
1001 | 250 | 1004 | |
1002 | 67 | 1005 | |
1002 | 23 | 1002 | 90 |
thank you
Serghei
It appears that the fourth column is the sum of second column based on the grouping of the first column. Is the answer in the fourth column what you are looking for? If not, show us a mocked up solution of what you expect.
Hi Serghei,
Try this in a new column
List.Sum(let _Acc = [Account] in Table.SelectRows(#"Changed Type", each [Description] = _Acc)[Amount])
See attached file.
Regards
Phil
Hi Philip,
this is exactly what I need. Thank you very much indeed!
Alan, yes, the fourth column is the final result that I was looking for.
thank you both,
Serghei
You're welcome.
Phil
Phil,
I am curious as to how you would do the same as asked with out regard to the column Account and only total based upon the change in Description using Serghi's sample data.
Thanks.
Alan
Hi Alan,
So the end result would look like this?
Description | Amount | SumColumn |
1001 | 150 | 600 |
1001 | 200 | 600 |
1001 | 250 | 600 |
1002 | 67 | 90 |
1002 | 23 | 90 |
You can use this
List.Sum(let _Desc = [Description] in Table.SelectRows(#"Changed Type", each [Description] = _Desc)[Amount])
Regards
Phil
Phil,
That is exactly what I came up with. I am guessing that to get them as Serghi has, we need another column filter on. Thanks very much. You have confirmed what I had.
Alan
No worries,
Phil
Hi Alan,
I think you have to use the Account column as the original post only had the totals where the Account column equals the Description column, which is not quite the same as where the Description column changes from the previous row.