Sum of bottom 4 rows

Hello Friends,
I have below 2 queries

  1. How to do sum of bottom last 4 rows. Output–>1124
  2. How to get bottom last 3rd date. Output–>-20-Mar

Can anyone help me in this.

Hi @Jeeru_venkat_Rao

Test.zip (42.1 KB)

This might help you

1 Like

@Jeeru_venkat_Rao

You can try as below

  1. Read the data into datatable…dt
    2 dt.AsEnumerable.Skip(dt.rowcount-4).Sum(function(x) cdbl(x("Sales").ToString)) will give you sum of last 4 rows
  2. To get last 3 dates into a separata datatable use dt.AsEnumerable.Skip(dt.rowcount-3).CopyToDataTable

Thse should be using in assign the first output is of type double second output is of type datatable

And i guess 335k is actually 335000 and in the data youw ould get the number only i guess

Cheers

1 Like

Hi @Jeeru_venkat_Rao

You can use Linq also
DT.AsEnumerable().Reverse().Take(4).Sum(Function(row) Convert.ToDecimal(row(“ColumnName”)))

Hope it will help :slightly_smiling_face:

Thank you so much for your quick response. Now I am able to solve the issue just because of you guys. @Anil_G, @Pavanraj_Shetty and @Gvivek9889 .

1 Like

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