I am using Views module. The view has three columns.
In the third column, I want a calculated percentage using the first two columns of the view.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI am using Views module. The view has three columns.
In the third column, I want a calculated percentage using the first two columns of the view.
If it's based on some rules, try using Computed Field and you can define the values via PHP code. Alternatively use Views PHP which allows you to directly use PHP inside views which may be useful for calculating percentage using the first two columns of your view.
You can use global php to acheive this (not recommended)
The best way to do it is by using this hook_views_pre_render(&$view) in your theme template file or in your custom module.
You can use Global:Math Expression in views to perform mathematical operations.
You would need tokens if you want to use your fields to perform calculations.
It is pretty simple to calculate percentage using this.
For example, to calculate percentage using two fields [field1] and [field2],
you can do it like
[field1]*100/[field2]
I hope its clear.