diff --git a/PxWeb/Code/Api2/DataSelection/Bjarte3.cs b/PxWeb/Code/Api2/DataSelection/Bjarte3.cs index 96e15988..465fcc81 100644 --- a/PxWeb/Code/Api2/DataSelection/Bjarte3.cs +++ b/PxWeb/Code/Api2/DataSelection/Bjarte3.cs @@ -270,7 +270,14 @@ private static void ReapplyCodelist(IPXModelBuilder builder, PXMeta meta) } else if (variable.CurrentGrouping != null) { - builder.ApplyGrouping(variable.Code, variable.GetGroupingInfoById(variable.CurrentGrouping.ID), GroupingIncludesType.AggregatedValues); + var grouping = variable.GetGroupingInfoById(variable.CurrentGrouping.ID); + + if (grouping is null) + { + throw new ArgumentException($"Could not find grouping {variable.CurrentGrouping.ID} for variable {variable.Code}"); + } + + builder.ApplyGrouping(variable.Code, variable.GetGroupingInfoById(variable.CurrentGrouping.ID), grouping.GroupPres); } else if (variable.CurrentValueSet != null) {