Get Timespan for percentage

Hello,

I am using Grafana v10.4.1 (d3ce857c0e) for Windows.

I want to calculate an percentage.

The information is queried from an influx db via fluxx.

For example I want to get the percentage of the time an machine is turned on:

QueryA Result: turned on time: 1800 (sec)
$Z : This is what is missing: I want to get the Timespan of my Dashboard.

Expression: Math: ($A / $Z) * 100

My question is: How can I get the timespan from the dashboard for my math expression?
Mayble I want / could do it in the fluxx query, I am open for this. But I am not getting it working.

Grafana provides $__from and $__to global variables:

  |> map(fn: (r) => ({ r with timeSpan: $__to - $__from }))