median() function

The median() function is a special application of the percentile() function that returns the median _value of an input table or all non-null records in the input table with values that fall within the 50th percentile depending on the method used.

Function type: Selector or Aggregate
Output data type: Object

median(method: "estimate_tdigest", compression: 0.0)

When using the estimate_tdigest or exact_mean methods, it outputs non-null records with values that fall within the 50th percentile.

When using the exact_selector method, it outputs the non-null record with the value that represents the 50th percentile.

The median() function can only be used with float value types. It is a special application of the percentile() function which uses an approximation implementation that requires floats. You can convert your value column to a float column using the toFloat() function.

Parameters

method

Defines the method of computation. Defaults to "estimate_tdigest".

Data type: String

The available options are:

estimate_tdigest

An aggregate method that uses a t-digest data structure to compute an accurate percentile estimate on large data sources.

exact_mean

An aggregate method that takes the average of the two points closest to the percentile value.

exact_selector

A selector method that returns the data point for which at least percentile points are less than.

compression

Indicates how many centroids to use when compressing the dataset. A larger number produces a more accurate result at the cost of increased memory requirements. Defaults to 1000.

Data type: Float

Examples

Median as an aggregate
from(bucket: "telegraf/autogen")
  |> filter(fn: (r) =>
    r._measurement == "mem" AND
    r._field == "used_percent"
  )
  |> range(start:-12h)
  |> window(every:10m)
  |> median()
Median as a selector
from(bucket: "telegraf/autogen")
  |> filter(fn: (r) =>
    r._measurement == "mem" AND
    r._field == "used_percent"
  )
  |> range(start:-12h)
  |> window(every:10m)
  |> median(method: "exact_selector")

Function definition

median = (method="estimate_tdigest", compression=0.0, tables=<-) =>
  percentile(percentile:0.5, method:method, compression:compression)

MEDIAN()

This documentation is open source. See a typo? Please, open an issue.


Need help getting up and running? Get Support