Need help with getting a Group by to work with data I get from a Distinct statement

Please read Formatting code and log snippets in posts and update your sample documents.