Axen_Rangs
Axen_Rangs

Reputation: 427

How can I use Datatable.compute() with list of data

I want to add values within list of dates using datatable.compute.

List of dates as follows

var dates = Enumerable.Range(0, 7).Select(days => monday.AddDays(days)).ToList();

And I want compute the values in those days.I don't know how to use filter with the list. I've tried following method but no luck.

sumObject1 = table.Compute("Sum(Amount)", "Type='Income' AND Date = dates");

Rest of the code works fine.

Upvotes: 0

Views: 801

Answers (1)

StefanFFM
StefanFFM

Reputation: 1898

You can use LINQ for that:

 table.AsEnumerable().Where(r => r["Type"]?.ToString() == "Income" && dates.Contains((DateTime)r["Date"]))
.Sum(rs => (decimal)rs["Amount"]);

You won't be able to use the list with the DataTable expressions.

Upvotes: 2

Related Questions