remove trailing spaces, replace tabs with 2 spaces
Make credit group bys work by declaring them as a separate table
The core report this is copied from has some involved painful coding that could be resolved by declaring the table twice with different aliases. I expect this is because the writer was unaware of that option. I have unravelled the credit group bys into a separate declaration - which gets us past the immediate fatal error