How to sum and average the whole column

Hello everyone,

I want to sum the data in the excel table in the picture, then I will take the average of this sum and print it in column C1 in the same excel file. what should I do?

note: the data in the excel file is printed as a string, not as int

I apologize for my bad English.

Project.zip (463.2 KB)

Hey @emir_ozsimsir , Please refer below file
BlankProcess1.zip (19.9 KB)

Hope it helps you !

1 Like

VB:
mySum | Datatype: Double = DtVar.AsEnumerable().Sum(Function (x) CDbl(x(“fiyat”).toString.Trim))

C#:

DtVar.AsEnumerable().Sum(x =>  Convert.ToDouble(x["fiyat"].ToString().Trim()))
1 Like

thank you very much sir it worked. but I cannot print it to excel because the data type is not data table, do you have any suggestions?

You can use write cell activity and add it in the excel
image
Define the cell and it will write

1 Like

When the localization plays a role (dot is group seperator) we can do

Int32.Parse(YourString, System.Globalization.CultureInfo.CreateSpecificCulture("tr-TR"))
Double.Parse(YourString, System.Globalization.CultureInfo.CreateSpecificCulture("tr-TR"))

2 Likes

I’m sorry, I don’t fully understand what exactly these codes are for, can you explain a little more?

Hi @emir_ozsimsir

Please find below xaml for your reference

BlankProcess5.zip (164.0 KB)

O/P Excel:
FORD.xlsx (14.2 KB)

I hope it helps!!

1 Like

Thank you very much, this is exactly what I was trying to learn. can you explain why you are using if else?

@emir_ozsimsir

Please find this xaml it contains two methods

BlankProcess5.zip (172.9 KB)

1 Like

@emir_ozsimsir

Method1:
In the given excel file it contains 1.100.000 so if we perform addition it doesn’t supports that’s why i am using if condition to filter it.

In 2nd method @ppr suggested conditions are helpful to read all values and performing addition.

So, better to use 2nd method because it reads all values to perform addition.

1 Like

I’ve learned a lot thanks to you

1 Like

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