I have to get unique country name and add all values for respective country

HI Team,
I have to get unique country name and add all values for respective country

Input:

Output like:

Please help anyone

Thanks
Shaik

Hi @Mukthar_Valli

Use build data table activity to create a datatable with required columns say dt_OutputData

Use The below linq

dt_OutputData = (From row In dtInput.AsEnumerable()
            Group row By country = row("Visited Country").ToString.Trim()
            Into grp = Group
            Select dt_OutputData.Rows.Add(
                country,
                 grp.First()("Date").tostring,
                grp.Sum(Function(r) Convert.ToDouble(r("Actual Number of Unique subscribers Registered")))
            )).CopyToDataTable()

if you want the 3rd column in same format use this

dt_OutputData = (From row In dtInput.AsEnumerable()
            Group row By country = row("Visited Country").ToString.Trim()
            Into grp = Group
            Let dateStr = grp.First()("Date").ToString
            Let valueConcat = String.Join("+", grp.Select(Function(r) r("Actual Number of Unique subscribers Registered").ToString.Trim()))
            Select dt_OutputData.Rows.Add(country, dateStr, valueConcat)).CopyToDataTable()

Hope this helps

1 Like

Hi @Sanjay_Bhat Code working fine but I have to some more columns values also

Can you provide take example of Columns like A,B,C,D

Thanks
Shaik

@Mukthar_Valli

You can add more columns this way and the values of these columns will the first value of the group
Make sure you add the columns in dt_OutputData

(From row In dtInput.AsEnumerable()
            Group row By country = row("Visited Country").ToString.Trim()
            Into grp = Group
            Select dt_OutputData.Rows.Add(
                country,
                 grp.First()("A").tostring,
                 grp.First()("B").tostring,
                 grp.First()("C").tostring
                grp.Sum(Function(r) Convert.ToDouble(r("Actual Number of Unique subscribers Registered")))
            )).CopyToDataTable()

Hope this helps!
Happy Automation :innocent:

@Sanjay_Bhat Thank you code working fine

Thanks
Shaik

1 Like

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