1. Calculation between measurements

In grafana, there is the possibility to make calculations between measurements via the Transform tab inside a panel.

Via the query editor, you could already do math operations between a measurement and constant values using the math statement. However. this does not have the ability to do calculations between measurements as indicated here.

Explore measurements - query data

1.1 Add a calculation

Go inside a particular panel from a dashboard and click the Transform tab in the middle left.

Next, click the Add field from calculation box to startup a calculation in the current panel.

images/grafana/grafana-transformation-0.png

In the Add field from calculation section , set the Mode dropdown to Binary operation to start a calculation.

Setting the Mode dropdown to Reduce , lets you reduce all values of the current measurements to one key value.

This behaviour is similar as the highlighting of a key value in a Stat . However, this functionality is almost never needed here.

Add a stat

images/grafana/grafana-transformation-1.png

Further, in the Operation dropdown on the left, select the first measurement for which you want to do a calculation as the 1st operand of the calculation.

In the Operator dropdown in the middle, select the according Calculation sign :

  • +
  • -
  • *
  • /

Select the second measurement for your calculation in the Operation dropdown on the right to be used as the 2nd operand in the calculation.

A good pratice is to Alias the output of the calculation to a new name, by giving in a name in the Alias entry .

This will be the name that is displayed in the Graph legend and is the name which could be used further to concatenate calculations between measurements.

Enable the Replace all fields slider to hide the current fields from the measurements which are used as operands in the calculation.

1.2 Concatenate calculations

To reuse the output of the first calculation between measurements, you can add another Add field from calculation transformation by clicking the Add transformation button at the bottom and selecting the Add field from calculation in the dropdown that appears.

To feed in the output of the previous calculation, use the name given as Alias in the previous calculation but now as an operand.

If the Replace all fields was selected in the previous calculation, it won’t be possible to reuse the operands from that calculation in the next one, only the output will be available as operand for the new calculation.