Sum of rows on multiple columns

Hi,
I have an input which looks like something below. Any Product can have only 1 data row or more than 1. For more than 1 data row I want to sum the values for its respective monthly columns.

i/p:

o/p:

File is attached as well.
Book1.xlsx (10.1 KB)

Hi @SunnyJha ,
use below query to achieve

(From row In dt.AsEnumerable() Group row By key=New with {row("Category").ToString(),row("ProductName").ToString(),row("ProductCode").ToString()} Into grp = Group Select New With { .Category = key, .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Apr))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("May))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Jun))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Jul))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Aug))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Sep))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Oct))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Nov))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Dec))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Jan))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Feb))), .SumValue1 = grp.Sum(Function(r) Convert.ToInt32(r("Mar))) }).ToList()

Regards,
Arivu

Try below
Sequence.xaml (9.8 KB)

(From row In dt_Input.AsEnumerable() Group row By Key1 = row("Country").ToString(), Key2 = row("ProductName").ToString(), Key3 = row("ProductCode").ToString() Into Group Select dt_Output.Rows.Add(Key1, Key2, Key3,  Group.Sum(Function(r) Convert.ToDecimal(r("Apr"))), Group.Sum(Function(r) Convert.ToDecimal(r("May"))), Group.Sum(Function(r) Convert.ToDecimal(r("Jun"))), Group.Sum(Function(r) Convert.ToDecimal(r("Jul"))), Group.Sum(Function(r) Convert.ToDecimal(r("Aug"))), Group.Sum(Function(r) Convert.ToDecimal(r("Sep"))), Group.Sum(Function(r) Convert.ToDecimal(r("Oct"))),Group.Sum(Function(r) Convert.ToDecimal(r("Nov"))), Group.Sum(Function(r) Convert.ToDecimal(r("Dec"))), Group.Sum(Function(r) Convert.ToDecimal(r("Jan"))), Group.Sum(Function(r) Convert.ToDecimal(r("Feb"))), Group.Sum(Function(r) Convert.ToDecimal(r("Mar"))))).CopyToDataTable()

Regards,
Arivu

1 Like

Hi buddy,
this logic ain’t working. can you share the xaml for this?

Try creating pivot table using UiPath and read range the value from output sheet

Better to start with manual pivot and see if the required results are coming.

Hi @SunnyJha ,
forum20250310_1.xaml (13.2 KB)
Let try this way
Hope it help,
LuongNV

1 Like

Hi @SunnyJha,

I have tested working fine. previously double quotes is missing attached working xaml file also. kindly gothrough
Sequence.xaml (9.8 KB)

Regards,
Arivu

1 Like

Thank you all for contributing to this thread. The solution is marked.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.