Two fields in two tables to be subtracted and put in a new field

Hello, I’m trying to obtain a new field that is the subtraction of two fields in two different tables. Tha syntax below is ok but gives no result, whereas the single queries get the right result.
Any suggestion what is wrong?
Many thanks

SELECT (non_negative_derivative(mean(“POWERPANNELLI”), 120s )- non_negative_derivative(mean(“POWERCASA”), 120s ))

AS “Consumo”

FROM (

SELECT mean(“ENERGY_Power”) AS “POWERCASA” FROM “telegraf”.“autogen”.“CASA” WHERE time > :dashboardTime: AND time < :upperDashboardTime: GROUP BY time(1m)

), (

SELECT mean(“ENERGY_Power”) AS “POWERPANNELLI” FROM “telegraf”.“autogen”.“Pannelli” WHERE time > :dashboardTime: AND time < :upperDashboardTime: GROUP BY time(1m)

)

GROUP BY time(1m) fill(null)

Hello @sorriso93,
You can’t perform math across measurements with Influxql. You need to use flux to do that. You could run a task and store the new values in a different measurement. You can enable flux in 1.7+.
Please take a look at this documentation:

And this blog: