# vb linq Count Distinct?

In the code bellow the NumberOfBooks does not return a count of distinct ISBNs. (If I have say 100 and 40 of them are the same ISBN I get a count of 100.) How can I have it return a count that would be based on Unique ISBN?

``````Dim results = (From r In dt.AsEnumerable()
Group By KeyEventArgs = "OneGroup" Into justOneGroup = Group
Select New With {
.NumberOfBooks = justOneGroup.Distinct.Count(Function(Books) Books.Field(Of String)("isbn")),
.CostPrice = justOneGroup.Sum(Function(c) c.Field(Of Decimal)("CostPriceTotal")),
.Qty = justOneGroup.Sum(Function(Books) Books.Field(Of Int32)("QtyLeft")),
.MaxQty = justOneGroup.Max(Function(Books) Books.Field(Of Int32)("MaxQty")),
.MinDate = justOneGroup.Min(Function(Books) Books.Field(Of Date)("FinalShipDate"))
}).ToList()
``````
LVL 1
###### Who is Participating?

x

RetiredCommented:
Hi Jess31;

Try it like this
``````Dim results = (From r In dt.AsEnumerable()
Group By KeyEventArgs = "OneGroup" Into justOneGroup = Group
Select New With {
.NumberOfBooks = justOneGroup.Select(Function(Book) Book.Field(Of String)("isbn")).Distinct().Count(),
.CostPrice = justOneGroup.Sum(Function(c) c.Field(Of Decimal)("CostPriceTotal")),
.Qty = justOneGroup.Sum(Function(Books) Books.Field(Of Int32)("QtyLeft")),
.MaxQty = justOneGroup.Max(Function(Books) Books.Field(Of Int32)("MaxQty")),
.MinDate = justOneGroup.Min(Function(Books) Books.Field(Of Date)("FinalShipDate"))
}).ToList()
``````
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.