diff --git a/Btms.Analytics/ImportNotificationsAggregationService.cs b/Btms.Analytics/ImportNotificationsAggregationService.cs index f2af39a..48f622c 100644 --- a/Btms.Analytics/ImportNotificationsAggregationService.cs +++ b/Btms.Analytics/ImportNotificationsAggregationService.cs @@ -72,7 +72,10 @@ public Task ByCommodityCount(DateTime from, DateTime to) .GroupBy(r => new { r.Key.ImportNotificationType, r.Key.Linked }) .ToList(); - var maxCommodities = result.Max(r => r.Max(i => i.Key.CommodityCount)); + // var maxCommodities = result.Max(r => r.Max(i => i.Key.CommodityCount)); + + var maxCommodities = result.Count > 0 ? + result.Max(r => r.Any() ? r.Max(i => i.Key.CommodityCount) : 0) : 0; var list = result .SelectMany(g => diff --git a/Btms.Analytics/MovementsAggregationService.cs b/Btms.Analytics/MovementsAggregationService.cs index 4d91fa6..940c5f1 100644 --- a/Btms.Analytics/MovementsAggregationService.cs +++ b/Btms.Analytics/MovementsAggregationService.cs @@ -68,8 +68,8 @@ public Task ByItemCount(DateTime from, DateTime to) var dictionary = mongoResult .ToDictionary(g => new { Title = AnalyticsHelpers.GetLinkedName(g.Linked), g.ItemCount }, g => g.Count); - var maxCount = mongoResult - .Max(r => r.Count); + var maxCount = mongoResult.Count > 0 ? + mongoResult.Max(r => r.Count) : 0; return Task.FromResult(AnalyticsHelpers.GetMovementSegments() .Select(title => new MultiSeriesDataset(title, "Item Count") { @@ -114,7 +114,8 @@ public Task ByUniqueDocumentReferenceCount(DateTime from, g => new { Title = AnalyticsHelpers.GetLinkedName(g.Linked), g.DocumentReferenceCount }, g => g.MovementCount); - var maxReferences = mongoResult.Max(r => r.DocumentReferenceCount); + var maxReferences = mongoResult.Count > 0 ? + mongoResult.Max(r => r.DocumentReferenceCount) : 0; return Task.FromResult(AnalyticsHelpers.GetMovementSegments() .Select(title => new MultiSeriesDataset(title, "Document Reference Count") {