How to Find Average of DataTable's Column

Hi everyone,

I am trying to get a data from a car selling website and average of first 100 ads’ car’s KM and price. Like in the below:

After finding average of 100 ads’ price and KM, I want to write it an excel cell which belongs to specific car brand.

How can I write an average of these ads to write cell activity ? Could you help me ?

Hi @ozgesdvc

Welcome to forum

Can u show the excel file where u need to write the avg?

Thank you Nived. This is the excel file ss:

Also this is the my uipath sequence:

Hi @ozgesdvc

For calculating the average u can use the below linq query

ExtractDataTable.AsEnumerable(). Average(Function(row) Cint(row (“columnname”)))

1 Like

Dear Nived,
Thank you for your help. It is working for KM because it’s all number. But it is not working in price because it contains “TL”.
It gives this error:
Write Cell: Conversion from string “200.000 TL” to type ‘Integer’ is not valid.

How can I fix this? Thank you.

Hi @ozgesdvc

Try this

ExtractDataTable.AsEnumerable(). Select (Function (row) row(“ColumnName”).ToString.Replace(“TL”,"")).CopyToDatatable.AsEnumerable().Average(Function (row) CDbl(row(“ColumnName”)))

It gives:
‘CopytoDatatable’ is not a member of ‘System.Data.EnumerableRowCollection(of String)’ error.