Submitting this as a feature request because I can't find an existing request for this functionality and it would really help in a lot of different use-cases:
We need a way to control date granularity on views aggregation settings. Currently date fields aggregate at the lowest level of the date field, which makes aggregation essentially useless when you want to aggregate on a date field. For example: I have nodes with a year-month-day date field and I want a simple view that shows me how many nodes exist with date field values for each year. I want:
2012: 47 nodes
2011: 122 nodes
2010: 34 nodes
I dive in and configure my view, setting up the typical aggregation settings needed for this type of thing. I hit a snag when I realize that the view is grouping on the full date field, aggregating only the rows that have the exact same month/day/year.
Something like http://drupal.org/project/views_date_format_sql, only for date module fields, not just system dates.
If anyone can inform me on how to aggregate my date field values by year only, that would be awesome; we can close this request.
Comments
Comment #1
naeluh CreditAttribution: naeluh commentedI would also be interested in this functionality.
I am using views Highcharts and also notice that it only takes the full date also because I entered in several date formats and they all returned the same view no matter which date format I used
thanks !
Nick
Comment #2
Ryan Osītis CreditAttribution: Ryan Osītis commentedI'm working on a sports site and this granularity would be perfect for aggregated stats displayed by year/season. Any ideas for a workaround?
Comment #3
naeluh CreditAttribution: naeluh commentedI would love to find one too.
but I don't think this works at all yet.
Comment #4
naeluh CreditAttribution: naeluh commentedI am willing to work on this if someone can help me get started fixing this issue
thanks !
Comment #5
naeluh CreditAttribution: naeluh commentedI am really interested in getting this functionality going is there any one that would want to help put this together ?
thanks
Comment #6
Norberto Ostallo CreditAttribution: Norberto Ostallo commentedI think you should take a look at Views Date Format SQL module. This could be a good starting point.
Comment #7
naeluh CreditAttribution: naeluh commentedthanks for the tip @Norberto Ostallo but it doesnt work with date field anymore the functionality got left behind somewhere http://drupal.org/node/1830436
Can you think of any other options ?
thanks again
Comment #8
naeluh CreditAttribution: naeluh commentedhttp://dev.client.gotpantheon.com/graph_example
Here is an example of the graph I am trying to build this should be 2 plots october and november with totals of all that fall on that month
Instead views outputs all of them and shows there respective month ?
thanks for any help
Nick
Comment #9
mpisano CreditAttribution: mpisano commented+1
Comment #10
rbrownell*Bump* This feature would be incredibly useful!
Comment #11
windmaomao CreditAttribution: windmaomao commented+1, can't do anything without it for reporting sites
Comment #12
mototribe CreditAttribution: mototribe commentedsame here
there seems to be a workaround:
I use a table layout, enabled aggreation, added field "nid" with "Count distinct".
I then add a sort by "post date" with "monthly" granularity.
Then I added a "post date" field with custom format "M-Y". I select "min" instead of "group results together.
Comment #13
naeluh CreditAttribution: naeluh commentedyeah I would like this for sure !
Comment #14
RoSk0@mototribe: Thank you very much! Your workaround is working(views 3)!
This issue should be noticed by maintainers
Comment #15
RoSk0No, not working. Showing minimum as expected.
Comment #16
cvharris CreditAttribution: cvharris commented@mototribe: I tried your workaround for my views aggregation and it worked so long as I only used a date sorting and did not add a field with the date included. I'd say RoSk0's concern is still worth looking into.
Comment #17
vanvemdenAgree, would be a very useful feature. Unfortunately mototribe's solution (#12) is not working for me.
Comment #18
teammk CreditAttribution: teammk commentedAnyone's found a solution for this ?
The workaround can't works for me, custom format is not available on my date field.
Anyone has found a patch for this ?
This module https://drupal.org/project/views_date_format_sql works only for systems date fields.
Up please !
Comment #19
Roensby CreditAttribution: Roensby commentedThis is my temporary solution for any entity such as nodes, users etc.
Just add a computed field to the entity, make it compute the granularity value of the date field and store the result in database - presto! You have a field in your entity that can be used to aggregate on behalf of the date field.
Example: we want to aggregate by month for a content type with a date field.
1. Install the computed fields module: https://drupal.org/project/computed_field
2. Make a note of your content types date fields machine name. Let's assume field_date
3. Add a computed field to the content type. As computed code, type in
The last line is converting a unix timestamp to the textual representation of a month. Replace 'F' with anything else, such as 'Y' for year, 'l' for day of week, aso.
Your date_field format might differ from mine, in which case - you need to modify the above.
4. Check "Store value in the database", otherwise the field is not available to views.
5. Once the field is added, resave all existing nodes of that content type ( use VBO or mass-publish from /admin/content )
6. Make a new view. Let's add Node ID (nid) and aggregate with count.
7. Add the computed field and aggregate with grouped by.
That's it!
If you want to sort the view, sorting by computed field in this case is no good, since we have months as text: we can only sort that field alphabetically.
Instead, add the date field to your sort criteria. Don't aggregate by grouping. Instead, choose average. Your months are now sorted by the date_field.
The good thing about this solution is that it is easy to remove, once the date module has support for granularity aggregation. Simply delete the computed field and fix the view :)
Comment #20
Marko B CreditAttribution: Marko B commentedThis solution from #19 is nice.
Comment #21
GAMe CreditAttribution: GAMe commentedIm trying to do the same thing however using #19 workaround with computed field im still not getting the result. Such a shame this isnt working in the date module.
*EDIT* After looking at #19 with fresh eyes today I realised I was being a bit of a muppet and had left in the start and end php tags. Doh! Thanks #19 :-)
Comment #22
secretsayan CreditAttribution: secretsayan commentedThanks @mototribe....your workaround is really cool....something to think about
Comment #23
pegahmajma CreditAttribution: pegahmajma commentedhi
I have solution that maybe good for someone:
I create format date in configuration with: Y-m
and in views>config of date field> choose this format for date
and with aggregation group with date.
it's work for me fine.
Comment #24
skadu@cchow's workaround in #19 works nicely. Thanks for that.
Comment #25
mooru CreditAttribution: mooru commented#19 works great but i had to remove the php tags and use computed field tools
Comment #26
moarli CreditAttribution: moarli commented#19 works great. thank you. How I can show the output in german?
Comment #27
jackjohnsonzm CreditAttribution: jackjohnsonzm commented#19 Roensby's workaround works just fine, thank you, similar issues to those found above, trying to aggregate by date.
Comment #28
stelmo CreditAttribution: stelmo as a volunteer commentedHello, I tried like pegahmajma #23 said and it doesn't work for me.