Writtng in excel

I am having a Doubt
i am reading excel file…
With for each activity i am looping through each cell of column “Name” and “Salary”
i want a Flow that if name repeating>1… then sum of the same name salary.

2 Likes

Hi @Satyam_Shrivastava

Can you share us a sample input and expected output

Assuming the input like below to be yours. I have done the flow:
→ Read Range Workbook
image
Output: dt_Input
→ Use Below syntax in Assign:

dt_Output = (From row In dt_Input.AsEnumerable()
                    Group row By Name = row.Field(Of String)("Name") Into Group
                    Let TotalSalary = Group.Sum(Function(x) Convert.ToDouble(x("Salary")))
                    Select dt_Input.Clone().Rows.Add(Name, TotalSalary)).CopyToDataTable()

dt_Output is of DataType System.Data.DataTable
→ Write Range Workbook dt_Output.
image

BlankProcess17.zip (46.8 KB)

Input Sheet is Input and Output sheet is Output.

Regards

2 Likes

@Satyam_Shrivastava

(From row In yourDataTableVar.AsEnumerable()
    Group row By key = New With {Key .Name = row.Field(Of String)("Name")} Into Group
    Let sumSalary = Group.Sum(Function(r) Convert.ToDouble(r.Field(Of Double)("Salary")))
    Select yourDataTableVar.Clone().Rows.Add(Group.First().ItemArray.Take(Group.First().ItemArray.Length - 1).Concat({sumSalary}).ToArray())).CopyToDataTable()

Sequence6.zip (1.8 KB)
Input:
image
Output:
image

1 Like

Hi @Satyam_Shrivastava

Follow the below approch.

Assign activity:
    nameSalaries = New Dictionary(Of String, Double)

For Each Row activity (ForEachRow in dt):
    If activity:
        Condition: nameSalaries.ContainsKey(row("Name").ToString())
        Then:
            Assign activity:
                nameSalaries(row("Name").ToString()) += CDbl(row("Salary").ToString())
        Else:
            Assign activity:
                nameSalaries(row("Name").ToString()) = CDbl(row("Salary").ToString())

For Each activity (item in nameSalaries):
    Log Message activity:
        Text: "Name: " + item.Key + ", Total Salary: " + item.Value.ToString()

Hope it helps!!

1 Like

Hi @Satyam_Shrivastava

Follow the zip file. Hope this will meet your requirement.

Regards

@pravallikapaluri
could you please let me know activity from scratch and what would be data tpe of
“nameSalaries”

@Satyam_Shrivastava

nameSalaries is of Dictionary Type
In the variables Panel,Go to Browse for types and type

1 Like

what would be data type… for this

nameSalaries(row(“Name”).ToString()) += CDbl(row(“Salary”).ToString())

@Satyam_Shrivastava

Use Assign activity
No need to any data type it is to save automatically in the current row of salary.

1 Like

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