Remove last point when querying

Hi. I’ve tried to drop the last data point as recommended in [INFLUXQL] Drop the Last Data Point with a combination of limit() and count() function: |> limit(n: (count()-1)) but i get an error:

 error @7:16-7:23: missing required argument tables error @7:24-7:25: expected stream[A] but found int error @7:16-7:25: stream[A] is not Subtractable

How I can drop the last point with self-calculation of a number of records, so I don’t have to enter the number of points manually?

Best regards,
Nikodem

Hello @Nikodemski2002,
Yes you can. I wish it was as easy as what you’ve described. Unfortunately you have to do the following instead

data = from...
range...
filter...

n_records = (data
|> count()
|> findRecord(
        fn: (key) => true,
        idx: 0,
    ))._value 

data |> limit(n: n_records) 

Lmk if you have any further questions.

Thanks @Anaisdg it works as should.

1 Like

@Nikodemski2002,
Sure thing! Btw what are you using InfluxDB for? I’m curious to learn about your project.
Thanks

Hi

Trying to do the same and found this post, but i have also found another way.
You can also use tail() with offset 1 and a big “n”.

By example I am tailoring my agrregate windows count data on each side of my time series doing:
data |> limit(n: 1000,offset: 1)
|> tail(n: 1000,offset: 1)

Or using the post solution:
data |> limit(n: data_count-2,offset: 1)
|> yield(name: “data_limit”)

Notice that in the exemple of the post there is a -1 missing to really remove one data.