How to get scalar from one query and use in another

I am trying to something extremely simple - I want to divide a value from a measure by the value from another measure, but the numerator is a scalar. Specifically I tried this and am just met with errors (Error: error in evaluating AST while starting program: type error 10:6-10:33: missing object properties (schema)):

n_cpus = from(bucket: "telegraf/autogen")
  |> range(start: dashboardTime)
  |> filter(fn: (r) => r._measurement == "system" and (r._field == "n_cpus" and == "x"))
  |> last()
  |> limit(n:1)
  |> getColumn(column: "_value")
  |> getRecord(idx: 0)

from(bucket: "telegraf/autogen")
  |> range(start: dashboardTime)
  |> filter(fn: (r) => r._measurement == "cpu" and (r._field == "usage_idle" and == "x"))  
  |> window(every: 10s)
  |> mean()  
  |> map(fn: (r) => ({
      r with
      _value: (100.0 - r._value) / float(v: n_cpus[0])
  |> group(columns: ["_time", "_start", "_stop", "_value"], mode: "except")

Any help? What am I doing wrong? The system does not like getColumn or getRecord, the two functions I thought would help me get a scalar from the stream.

Anyone? I just want to have a way in influxdb using either InfluxQL or Fluxlang to divide one series by a constant value that comes from another measurement. In this case, I want to divide CPU usage by number of cores.

I was using Kapacitor/Ticksript .

This may give you an idea, though i was doing it for Process.
Objective is to get .exe(executable) cpu usage divided by the number of cpu present on the server and then graph it out on Grafana.

Though stream would be better for alerting but if you care to just store the aggregated values then batch would be fine.

If abc.exe shows 20% of cpu usage on a server which has 4 cpus then do the following math 20\4 = 5% (cpu usage of abc.exe is 5%)
Below tickscript also groups all the similar processes using regex.

    var process = batch
        |query('SELECT Percent_Processor_Time as cpu_time FROM "test_server"."autogen"."Process" WHERE "instance" =~ /^WmiPrvSE*/')

// This is to get number of cpus from each host
var system = batch
    |query('SELECT n_cpus as n_cpus FROM "test_server"."autogen"."system"')

var joined_data = process
        .as('process', 'system')

var perform = joined_data
    |eval(lambda: "process.cpu_time" / "system.n_cpus")
        .tag('instance', 'Wmi*')

Thanks, that helped put me on the right track.