Calculating totals, minimum, maximum and average values in WordPress Tables

Video versionA video overview of responsive tables in wpDataTables

Sum/Totals row in wpDataTablesHow to show totals for numeric columns in tables

For many cases, it is useful to calculate a sum, average, minimum and maximum of all the values for a given column. For example, total sales within a month, the total price of products in an order, calculating maximum profit, minimum wage, average grade etc. wpDataTables supports a sum / totals, average, minimum and maximum row for numeric columns, see this table as an example, and try to filter it by a date range to see how the totals recalculate:

Adding all these features is simple. In the column settings, click on the Data tab and check the Calculate checkboxes for the selected column you want to calculate these functions.

Calculation functions

If these checkboxes are checked for at least one row, a functions row will appear in the bottom.
Functions are recalculated on table redraw (i.e. when you filter).

Also take note of the shortcode below each calculated function.

Calculation functions shortcodes

By pasting the shortcode, you can display the results of the functions somewhere outside the table, or you can paste this code in a cell belonging to another table.
To achieve this you will need to check the Parse shortcodes option on the wpDataTables Settings page.

Parse shortcode option
  1. Go to WordPress admin, and open wpDataTables
  2. Click on Settings
  3. Check the “Parse shortcodes” checkbox

Please note that calculation functions cannot be used in wpDataCharts and in the Simple table.