I'm looking for a way to add sorting and/or grouping by county to reports. Specifically, Membership Details and constituent Details. I've tried a bit of monkeying with the PHP but I don't seem to have a good enough grasp of it. I'm running v4.7.6. Thank you.


Ah yes unfortunately you will need some PHP edits to make that work; Custom reports in CiviCRM are a good way to start getting into the code base though!

Here's two references for you: https://sf2012.civicrm.org/sites/default/files/slides/CiviCRM%20Reports-Customize%20and%20Extend.pdf




Those two reports work differently.

In most reports, there's an array called columns that determines which fields are available. However, to make reports more standard, there's a simple function "getAddressColumns" a report can call if they just need standard address columns. Not all reports can use the standard columns, and not all have been converted over (if it ain't broke etc.), but some have.

Membership Detail report is one of those reports that have been converted - and so it should definitely have the county field. See screenshot. Membership Detail report screenshot

Constituent Detail does NOT use that function. To add the column:

  • Edit <civicrmroot>/CRM/Report/Form/Contact/Detail.php.
  • In the section civicrm_address (around line 143), add the county_id field to the array. Copy the style of "state_province_id".
  • That will let you select the column, but it will show as an ID, not the county name. In the alterDisplay function, copy the state_province_id handling (around line 887) and change all the references to county_id from state_province_id.

That should at least get your counties displaying! I'll let KarinG's answer suffice for getting your sorting/grouping working.

Finally - you can always use exports instead of reports, and group in your favorite spreadsheet program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.