I have two separate fields in a View:

  1. Miles on Engine at Time of Purchase/Delivery (field_engine_hours_at_delivery)
  2. 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

<?php $display_output = $entity_field_item['value']; ?>

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->field_engine_hours_at_delivery'))) + array_pop(array_pop(field_get_items($entity_type, $entity, '$row->field_util_agg_engine_hours')));


2 Answers 2


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


I ended up getting it to work. I left the Value Code field blank and added this code to the Output Code:

print $data->_field_data['nid']['entity']->field_engine_hours_at_delivery['und'][0]['value'] +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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