If you have a field collection(e.g. field_transaction) that have quantity field (e.g field_stock_quantity) and you want to sum all the quantity up. Here is code to do it in Computed Field module:
$field_items = field_get_items($entity_type, $entity, 'field_transaction'); $total = 0; foreach ($field_items as $item) { // Note: I don't know why 'und' is within the field collection. // Is there a better way to get the value of field_stock_quantity? $total += $item['field_stock_quantity']['und'][0]['value']; } $entity_field[0]['value'] = $total;