How to SUM/add the values of two fields in a View? I have two separate fields in a View:


Miles on Engine at Time of Purchase/Delivery (field_engine_hours_at_delivery)
Miles added to Engine After Purchase/Delivery (field_util_agg_engine_hours)


(1) is a standard integer field. (2) is fed by an aggregation of many other content items. My view is set to display these two values in a table, side by side.

I would like to now add those two fields to get a "Total Miles on Engine" value for the view. I tried adding a Views PHP field with the following PHP code, but the result that is returned is blank.

Value Code

$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_engine_hours_at_delivery'))) + array_pop(array_pop(field_get_items($entity_type, $entity, 'field_util_agg_engine_hours')));


Output Code


  &lt;?php $display_output = $entity_field_item['value']; ?&gt;


I'm not very well-versed in PHP, so I'm sure I've got something amiss in that code. Can anyone clarify whether this can be done... and if it can, what I need to change in my code to make it work?

P.S., I also tried this version of the Value Code, but still did not get any result:

$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, '$row-&gt;field_engine_hours_at_delivery'))) + array_pop(array_pop(field_get_items($entity_type, $entity, '$row-&gt;field_util_agg_engine_hours')));


Thanks!
There's a module for that: Views Calc allows you to SUM, AVERAGE, COUNT, MIN, MAX, or AVG selected columns in Views.