Sort and work with DataTable

I have a Data Table which I collect the expenses of a house (expenses, date …) I want to order the expenses by name and add the total of each expense.

For example if I have food, insurance, gym … I want to group each row of food, each row of gym… and add the total of that expense.

How can I do it? Thanks!

Hi @Carmen_Tur

Here is the sample,

Dim Amounts As New DataTable 'Your code to load actual DataTable here
Dim amountGrpByDates = From row In Amounts
Group row By dateGroup = New With {
Key .Yr = row.Field(Of Integer)(“Yr”),
Key .Mnth = row.Field(Of Integer)(“Mnth”),
Key .Period = row.Field(Of String)(“Period”)
} Into Group
Select New With {
Key .Dates = dateGroup,
.SumAmount = Group.Sum(Function(x) x.Field(Of Decimal)(“Amount”))}

Hope this will help you. Thank you.

1 Like

Hey @Carmen_Tur,

You can use the for each loop activity and iterate through all the rows.

Create one expense variable and inside for each loop you can add expense=Covert.ToDouble(item.tostring)
Make sure your variable expense is of the type double.

Cheers @Carmen_Tur

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