Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Views Simple Math Field

Security covered Under active development 2,136 sites

Part of the Views ecosystem · 286 projects

This module allows you to perform mathematical operations on fields within a Drupal view. It provides a simple math field that lets you select fields and define an expression to calculate a new value. This is useful for site-builders who want to avoid using Twig for calculations or need a more robust solution for complex data manipulation.

Based on https://www.drupal.org/project/views_cumulative_field, this module allows you to perform simple math expressions on two Views fields.

I created this because Drupal 8 Ctools does not currently have the Global Math Expression field that it had in Drupal 7.

Note: Twig can do math, but it's better to do math with PHP. This field is especially useful for site-builders who want to avoid Twig or who have a module like Charts that responds better to this module than a field rewrite.

Instructions

After you enable this module (you may need to run cron/clear caches):

  1. Create/edit your view.
  2. Add fields as values on which you will perform your operation.
  3. Add the "Global: Simple Math Field" field (created by this module).
  4. Select the fields, and then add their tokens (e.g. @field_one) into the text area. An example operation could be '(@field_one / @field_two) * 100'.

That's it!

Versions

8.x-2.x

This version allows users to add multiple fields and operations into the same formula. It makes use of the "Eval-math" library. There is currently no upgrade path from 1.x to 2.x, but it's relatively easy to re-configure existing Views Simple Math Fields once you have updated (edit the view, configure the field, save). Would love someone to contribute an upgrade path! Here's what the 2.x field looks like:

3.0.x

This is nearly identical to 8.x-2.x, except it now relies on a fork of the "Eval-math" library to accommodate PHP 8+.

Contributing

If you are interested in helping out with this module, please submit patches or contact me directly.

Drupal 8–11

Ask your assistant about Views Simple Math Field

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • views Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jun 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
3.0.2 Stable 8–11 Jun 26, 2024