Quantile and count in one query

Hi, today I tried switching from mongo timeseries to influx 2.2

I am trying to get count and quantile in one query

Would something like this be possible? Or do I need to write my own map/reducer code?

This works, pretty happy with this :slight_smile:

from(bucket: "itsjustatest")
     |> range(start: -10d)
     |> group(columns: ["somegroup"])
     |> quantile(q: 0.75)

but I need this ā€¦ (which obviously does not work)

from(bucket: "itsjustatest")
     |> range(start: -10d)
     |> group(columns: ["somegroup"])
     |> quantile(q: 0.75) as quantile and count() as count

Is there a way to do this using the native quantile and count ?

Hello @Arjen,
Absolutely! Welcome to Flux. It takes a second to get used to it especially if you come from InfluxQL or SQL.

Iā€™d love to recommend the following resources:

You can do the following:

data = from(bucket: "itsjustatest")
     |> range(start: -10d)
     |> group(columns: ["somegroup"])

data |> quantile(q: 0.75)
|> yield(name: "quantile") 

data |> quantile(q: 0.75)
|> yield(name: "count") 

Anaisdg thank you for this answer! I do like how this is done :slight_smile:

1 Like

I have tried it, works great. However doing this will give me 2 tables/rows. Using join I will get 3 rows :slight_smile:
Is there any way just to have the data like

{quantile:123,count:123,field:'somevalue'}
{quantile:456,count:456,field:'anothervalue'}