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.

  • Assuming your first 2 columns correspond to 2 fields of a node (for each row), you could use the math_field module which does NOT (repeat NOT) require the dangerous PHP filter. For more details, refer to my answer at drupal.stackexchange.com/questions/183045/… – Pierre.Vriens Dec 8 '15 at 22:33

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.

  • 1
    i do not want to use views php.I wil try using computed fields module.thanks. – Tulika Sharma Nov 13 '15 at 10:01
  • 1
    @kenorb: You are also correct. But using php in views is major issue for performance right..... And to change single field value may be we can go for hooks that provided by views rather than usinb other contrib module. – Ajay Reddy Nov 13 '15 at 10:02
  • @AAjayKumarReddy If Views has caching on that page, field won't be re-calculated anyway, so it'll be quick in the same way. Secondly using PHP won't make the performance worse than the standard field which running a lot of other functions to call (e.g. field formatters). – kenorb Nov 13 '15 at 10:19
  • @kenorb read the answer to this and the comments What are the downsides of using 'custom' PHP code in blocks, nodes, views-args, etc? – No Sssweat Nov 13 '15 at 12:15

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


I hope its clear.


Not the answer you're looking for? Browse other questions tagged or ask your own question.