You should see the logic in the view for general_reports/_report_data_rows.

I'll see what I can do about moving it somewhere else.