How to use the number of rows as as variable for another function?

Hello

I have a table for which I apply count() function, and get the number of rows in the _value column

My goal is to assign this number to a variable and use math fucntions on it, and use it on another queries.

Like this:

//count the rows
numberofrows = from(bucket: “ECTELEM”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “interface_stats”)
|> filter(fn: (r) => r[“hostname”] == “host”)
|> filter(fn: (r) => r[“_field”] == “bytes_rx”)
|> count(column: “_value”)

// get the number equal to 5% of the rows in a table
x = numberofrows * 0.05

// get top 5% of the rows
top5persentofrows = from(bucket: “ECTELEM”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “interface_stats”)
|> filter(fn: (r) => r[“hostname”] == “host”)
|> filter(fn: (r) => r[“_field”] == “bytes_rx”)
|> top(x)

But it does not work. I can not use _value from numberofrows as an integer or float.

x = numberofrows._value * 0.05
x = numberofrows._value.toUint() * 0.05
also does not work

How to do it?