What version of Druid are you on?
There was a bug in an older version of Calcite that was remedied by
https://github.com/apache/druid/pull/14510 ... don't know if this is what you are hitting up against.
You can also try true/false combinations of useApproximateCountDistinct and useGroupingSetForExactDistinct to see if that affects your result.