Screenshot of a Views Chart using a Cumulative Field

This module creates a Views field handler that enables you to calculate the cumulative value of another field in your view. This is great for Views displays created by the Charts module, but can be used for any View that allows fields.

It was inspired by this comment on the Views PHP module page:

While this module allows you to directly use PHP inside views which may be useful for quick and easy solutions, it is highly advisable to use regular handlers and plugins when available (or even to create one yourself).

and this related post: 44,497 People Are Wrong: How to NEVER Need Views PHP.

Instructions

After you enable this module:

  1. Create/edit your view.
  2. Add a field that outputs numbers. This is considered the "data field" for purposes of this module.
  3. Add the "Global: Cumulative Field" field (created by this module)
  4. In cumulative field's field settings, select the field for which you want a cumulative value (the "data field") from the radios.

That's it! The "Cumulative Field" should add all the previous rows' values with the current row's value at each row.

Related Module

If you want a Views field to perform simple math expressions, try this one: https://www.drupal.org/project/views_simple_math_field

Credit

Thanks to Marton Bodonyi (codesidekick) via Database independent Views 3 custom field handlers for the majority of the code used for the 7.x branch and Danny Sipos (upchuk) via Creating a custom Views field in Drupal 8 for the code for the 8.x branch. I also received support from Elias Muluneh.

Project information

Releases