Skip to main content

How to create custom column

While the extension already defines numerous columns with typical calculations, custom columns are useful when you need unique formulas or non-typical data combinations. Custom columns are created with the Config Builder.

  1. Go to Reports -> Advanced Reports -> Reports, click Config Builder above the reports list, and then click Add New Config.
  2. Enter a Title. This name is for internal use only, to find the config in the configs list.
  3. Define the column as a JSON config in the editor. You can start from Insert -> Calculated money column and adapt it. The structure of the config is described in The structure of a config.
  4. Open the Test tab next to the editor and click Run for your column to see its values for 10 rows of your database.
  5. Click Check against schema to make sure the config is valid.
  6. Click Save. The column is available in reports right away.
  7. Open a report built on the same explore, add the column with the column picker, and check the values.

Here is an example of a custom column that calculates the gross profit based on invoiced amounts. More useful examples can be found in the relevant section of the manual.

{
"datasets": [
{
"name": "sales_order",
"columns": [
{
"name": "custom_gross_profit",
"label": "Custom Gross Profit",
"kind": "measure",
"type": "number",
"value_format": "money",
"aggregation": "sum",
"expr": "(sales_order.base_subtotal_invoiced - IFNULL(sales_order.base_total_invoiced_cost, 0) - IFNULL(sales_order.base_total_refunded, 0)) * IF(sales_order.base_to_global_rate > 0, sales_order.base_to_global_rate, 1)",
"store_expr": "sales_order.base_subtotal_invoiced - IFNULL(sales_order.base_total_invoiced_cost, 0) - IFNULL(sales_order.base_total_refunded, 0)"
}
]
}
],
"explores": []
}
tip

Every column reference in expr must be fully qualified as dataset.column, for example sales_order.base_grand_total. To find the right reference, click the column on the Schema tab next to the editor.