Get next integer value

I have a datatable with name and amount(in decimal).. I have to group by based on name and find sum of amount. The final sum should be integer format

Eg
Name amount
A 10.99
A 9.05
B 8.95
B 99.99

Expected output

Name amount
A 21
B 109

Output that I am able to get
A 20.04
B 108.94

I am using linq with groupby.. Can someone help here to get output in next interger

You can use below code with Invoke code activity
Parameters: out_resultTable , in_dataTable

out_resultTable =in_dataTable.AsEnumerable().
    GroupBy(Function(r) r.Field(Of String)("Name")).
    Aggregate(New DataTable(), Function(dt, g)
        If dt.Columns.Count = 0 Then
            dt.Columns.Add("Name", GetType(String))
            dt.Columns.Add("Amount", GetType(Integer))
        End If
        dt.Rows.Add(g.Key, g.Sum(Function(r) CInt(Math.Round(r.Field(Of Decimal)("Amount")))))
        Return dt
    End Function)


Hi @pandeypriyanka1312

Use in your linq " Math.Ceiling " rounds up to the next integer, so sums like 20.04 become 21, 108.94 becomes 109 same what you want.

Happy Automation

1 Like

Thanks @prashant1603765

1 Like

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