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

From version 5.7, the calculation functions can also be used in Formula Columns.

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

Each calculation function shortcode have additional parameters that can be useful:

  • label – You can overwrite label throw this shortcode parameter for example for sum(can be used for all shortcode calculation functions)

[wpdatatable_sum table_id=2846 col_id=23013 label="My SUM label"]

By default this parameter is null and will be used value from Global label settings.

  • value_only – If you need to show only value, without additional html around it you can pass this parameter with value 1. By default is set on 0. For example for average function to show only value (can be used for all calculation shortcode functions)

[wpdatatable_avg table_id=2846 col_id=23013 value_only=1]

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