Calculating average speed
Last updated on
30 April 2025
D'Arcy Norman has a Computed Field example in which he calculates the average speed of a bike trip, rather than filling it in manually:
Computed Field settings (leaving other fields at their defaults):
- Computed Code:
$node_field[0]['value'] = ($node->field_distance[0]['value'] / $node->field_duration[0]['value']) * 60; - Check 'Store using the database settings below
- Data Type: float
- Data Length: 10,2
- Default Value: 0
- Check 'Sortable' to make the field sortable in views.
The end result can then be displayed in a sortable view.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion