 # Column order sequence generator

Hi there,
I would like a way to generate a linear sequence from an order operation.
Let me explain with an example where I select a certain range and I have to sort the kWh consumption in descending order.

``````from(bucket: "site_monitoring/autogen")
|> range(start: dashboardTime)
|> filter(fn: (r) => r._measurement == "gas" and (r._field == "kWh"))
|> sort(columns: ["kWh"], desc: true)
|> limit(n:10, offset: 0)
``````

I now want to generate a column called order that contains the linear sequence from 1 to 10.
This is basically a duration curve that I then plot in Grafana via XY plot.
Any help would be appreciated as I can’t find a useful function for generating it.

Hello @Paul_Lee,
Hello @Chris_King ,
You can perform an incrementing value column with

``````|> map(fn: (r) => ({r with x: 1.0}))
|> cumulativeSum(columns: ["x"])
``````
1 Like

Hi,
very elegant solution, is there a way to convert the float to int?
I also tried this:

``````import "date"
from(bucket: "primary_school/autogen")
|> range(start: dashboardTime)
|> filter(fn: (r) => r._measurement == "gas" and (r._field == "kWh"))
|> sort(columns: ["_value"], desc: true)
|> limit(n:4, offset: 0)
|> map(fn: (r) => ({r with _order: 1}))
|> cumulativeSum(columns: ["_order"])
|> map(fn:(r) => ({ r with _orderint: int(v: r._order) }))
``````

but the field _orderint is a float.