In theory you may fork Grafana and create custom transformation for it. But I would say it will be terrible solution from the performance perspective if you have many datapoints. I would rather use another TSDB supported by Grafana, which support this kind of math natively.