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) »
  • How to report membership trend over time?
Pages: [1]

Author Topic: How to report membership trend over time?  (Read 1244 times)

JulieR

  • I post occasionally
  • **
  • Posts: 52
  • Karma: 5
How to report membership trend over time?
May 08, 2011, 04:31:19 am
I need to create a report that will allow me to graph the trend in our membership over time.  I want to be able to plot current member count by date, preferably for different membership types, so we can track the effect of diffferent membership drives.

For any historical date, e.g. 1 March 2010, I can see how many members I had using
select count(*) from civicrm_membership where "2010-03-01" between start_date and end_date;

So one option would be to put ths in a loop, either in a stored procedure or in php, and execute it substituting the first day of each month for the specified years. I'm not exactly sure how one would do this, but it seems plausible. But I'm also wondering whether there is a better way, or someone has already done something like this?  It seems like an obvious thing to want to do.  Is there a report type I have missed?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to report membership trend over time?
May 08, 2011, 04:46:33 am
I don't think CiviReport can handle this, but yes, you can certainly do it in PHP. If you don't know the specifics of how to do that, I would consider hiring a programmer.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: How to report membership trend over time?
May 12, 2011, 08:54:09 am
OK - so it looks like a new report.

I am unsure as to whether CiviReport allows you to / if there is a suggest method for looping SQL queries.

The query that you would need to loop would be something like the following (where date is the intervals that you want to measure).

SELECT '2011-01-01' INTO @date;
SELECT civicrm_membership_type.name, count(civicrm_membership.id)
FROM civicrm_membership
RIGHT JOIN civicrm_membership_type ON civicrm_membership_type.id=civicrm_membership.membership_type_id
WHERE start_date < @date AND end_date < @date GROUP BY membership_type_id;

Any suggestions?
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to report membership trend over time?
May 12, 2011, 09:53:35 am

You should be able to create temp tables in your reporting code and use those temp tables to generate the report

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: How to report membership trend over time?
September 21, 2011, 09:01:02 am
JulieR says "BTW there was a typo in your SQL: WHERE start_date < @date AND end_date < @date - you need end_date > @date.  This is why I tend to use the more readable between operator: WHERE @date BETWEEN start_date AND end_date."

Agree that this is a better approach to writing this query :)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Re: How to report membership trend over time?
October 24, 2011, 11:01:17 am
I'm looking for something along these lines as well, has anyone written something they are willing to share?

I really want to be able to graph membership by month over time. Ideally I would have a graph showing renewals, lapses, and new members per month for the past couple of years.

Worst case I'll write something in PHP using the GD libraries, but I don't have time to even think about it for the next month or so. (which is why I'm hoping someone else has already done it! :-) )
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: How to report membership trend over time?
November 08, 2011, 07:21:48 am
I've done part of this job, but not complete.  Written for v3.3.6.

I've put the report TPL and PHP here:
http://www.phdcc.com/download/civicrm/MemberCount.zip
Put these in your custom template and PHP folders CRM/Report/Form/Member/

You need to Register New Report Template, as described in here:
http://wiki.civicrm.org/confluence/display/CRMDOC40/Creating+A+Report+Template+Extension

It's hardwired as follows in two places:
  civicrm_membership_type.id=7 AND contact_type='Organization'
so you'll need to change/remove that.

The Frequency selection does work, but the date range criteria isn't acted on.

The mian work is in the select() function which
- creates a temporary table
- gets the first membership join date
- loops through all dates from then until now, inserting the member count at each date

I haven't been able to complete this report code yet, but thought it may be useful "as is".

Chris

sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Re: How to report membership trend over time?
November 08, 2011, 01:13:32 pm
Thanks!  I'll have to find some time to give this a try in the next few days.
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • How to report membership trend over time?

This forum was archived on 2017-11-26.