
When to use table calculations
Typically, in your Lightdash project, you’ll have one or more Tables that you’ve pre-defined in your dbt project (this is probably done by the data analysts/engineers/analytics engineers). But sometimes, you’ll need particular logic which hasn’t been defined as a dimension or metric in your dbt project - maybe because you have a new kind of question or use case. This is when you might need a table calculation. Watch out: table calculations can be easier to create than regular metrics/dimensions, but they are not as easy to manage. If you find yourself creating the same table calculation over and over again when you’re using a Table, then it might be worth adding it in as a more permanent metric in your dbt project! You can read more about adding metrics to your dbt project here.Creating table calculations
Before you create a table calculation, you need to add some dimensions and/or metrics to your results table. Table calculations can only be built using the dimensions + metrics that you’ve included in your results table. So, to create a table calculation, first, you need to add the dimensions and/or metrics for your table calculation to your results table.Using Quick Calculations
Quick calculations are shortcuts to the most common table calculations, these are only available to metrics in the contextual menu in the results table.
Using Custom Table Calculations
Once you’ve got some data in your results table, you can create a table calculation by clicking on the+ Table calculation
in the Results
tab of the Explore view:

Write the SQL for your table calculation in the pop-up box
Your table calculation is defined using raw SQL that you write up in this pop up box. If you’re not sure what to write here, you can check out some of our table calculation SQL templates. To reference the metrics and dimensions in your results table, you can either use the autocomplete, or you can manually write the full field name using the format${table_name.field_name}
.

Update the format of your table calculation (if needed)
If needed, you can update the format of your table calculation to things like percent formatting using theformat
tab.

Format types | Description | Raw value | How it might look like in Lightdash |
---|---|---|---|
Default | Default format for the table calculation result | 0.75 | 0.75 |
Percent | Converts numbers into a percentage | 0.75 | 75% |
Currency | Adds currency symbol and default locale format | 1234.1234 | $ 1234.12 |
Number | Formats number with prefix and suffix | 123.1234 | Speed: 123.12 km/h |
To delete or edit your table calculation, just click on the gear icon by the field name
If you need to edit or delete a table calculation, you can just click on the toggle beside the field and do what you need to do!