CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Calculated field in a report
Pages: [1]

Author Topic: Calculated field in a report  (Read 1321 times)

matthewboh

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 2
Calculated field in a report
July 08, 2012, 09:06:45 am
I've gotten all the selection code written and debugged for a report that puts ages into certain demographic groups. However, nothing is showing after that, so I know it's got to be something in the reporting template.

I'm not showing any fields from the underlying databases, it's just a calculated field and then the count of the people. Here's an example of the output
Code: [Select]
+-------------------+---------------------------+
| agerange          | count(civicrm_contact.id) |
+-------------------+---------------------------+
| 18 and under      |                         7 |
| Between 19 and 25 |                        35 |
| Between 26 and 40 |                       230 |
| Between 41 and 60 |                       313 |
| Over 60           |                       162 |
| Unknown           |                       865 |
+-------------------+---------------------------+
6 rows in set (0.01 sec)

All I'm getting on the screen is:

Code: [Select]
Row(s) Listed 6
So I'm assuming that I have to create a custom template. Are there any examples floating around? Can someone point me to something? Can I take some current report code and create it easily? I'll also want to allow for pie charts and bar charts.

Thanks as always!

Deepak Srivastava

  • Ask me questions
  • ****
  • Posts: 677
  • Karma: 65
Re: Calculated field in a report
July 10, 2012, 02:27:58 am
Here are some examples for computed columns:
- percentage-change filter of Repeat Contributions Report, CRM/Report/Form/Contribute/Repeat.php
- Amount Received column of Personal Campaign Page Report, CRM/Report/Form/Contribute/PCP.php
- count columns are there almost in all summary reports. One is contribution summary report, 'Amount Statistics' display column.

If you look at http://wiki.civicrm.org/confluence/display/CRMDOC/CiviReport+structure+and+customization, "case I: shortcut method" shows how to add columns using _columnHeaders. Using same rule you could add any column (need not be a existing column) and fill it using your query.

alterDisplay() function is where you could modify / add your age-range strings.

I don't think you will have to modify your report template. If you have your query ready and know how to fill column values using above rules, should work fine.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Calculated field in a report

This forum was archived on 2017-11-26.