How to get sum of a column after grouping on two columns

I have a table which has the below schema. I need to get the sum of the quantity for each part number, by grouping the rows on both part_number and unit_price.

Schema: (part_number | unit_price | quantity)

I have seen this GroupBy method in LINQ. But I am not sure whether we can use it to get my solution.

Additionally, I saw a Compute() on data table which can be used to calculate the sum/average etc. on data table columns.

But, I am unable to figure out how to select the sum of quantity, by grouping on two columns (part_no, unit_price). A little help would be really appreciated.

Thanks in advance.


I would ask if whether you are going to process each part number in your process. Because, then you can take the Sum of each part number as you loop through each one.
Then, you could just use .Where and .Sum

Here is some discussion on GroupBy and Sum that may help, since I have a bad memory:

1 Like

Firstly use excel application scope , use for each loop then inside it try to extract the values of column(part_number) from excel sheet and store in a variable of string type similarly extract the values of column(unit_price) from excel sheet and store in a variable of string type then use third variable of string type and store adding of previous two variables (all this do inside excel application scope then inside for loop). I think that will help you.

Hi ClaytonM, thanks for the quick reply. Your solution looks helpful. I will give a try and get back. But, could you help me to modify it to group by both columns. I went through the query. But, If I can get some explanation about how the query is built, that would be great help. I just need to understand the query…:slight_smile: