Functions for stats, chart, and timechart
Functions for stats, chart, and timechart
These are statistical functions that you can use with the
chart
,
stats
, and
timechart
commands.
 Functions that are relevant for stats are also relevant for
eventstats
andstreamstats
.  Functions that are relevant for chart, stats, and timechart are also relevant for their respective summary indexing counterparts:
sichart
,sistats
, andsitimechart
.  Functions that are relevant for sparklines will say as much. Note that sparklines is not a search command, it is a function that applies only to
chart
andstats
and allows you to call other functions. For more information, read "Add sparklines to search results" in the Search Manual.
Function  Description  Command(s)  Example(s) 

avg(X)
 This function returns the average of the values of field X. See also, mean(X).  chart , stats , timechart , sparkline()
 This examples returns the average response time:

c(X)  count(X)
 This function returns the number of occurrences of the field X. To indicate a specific field value to match, format X as eval(field="value").  chart , stats , timechart , sparkline()
 This example returns the count of events where status has the value "404":
These generate sparklines for the counts of events. The first looks at the

dc(X)  distinct_count(X)
 This function returns the count of distinct values of the field X.  chart , stats , timechart , sparkline()
 This example generates sparklines for the distinct count of devices and renames the field, "numdevices":
This example counts the distinct sources for each sourcetype, and buckets the count for each five minute spans:

earliest(X)
 This function returns the chronologically earliest seen occurrence of a value of a field X.  chart , stats , timechart
 
estdc(X)
 This function returns the estimated count of the distinct values of the field X.  chart , stats , timechart
 
estdc_error(X)
 This function returns the theoretical error of the estimated count of the distinct values of the field X. The error represents a ratio of abs(estimate_value  real_value)/real_value.  chart , stats , timechart
 
first(X)
 This function returns the first seen value of the field X. In general, the first seen value of the field is the most recent instance of this field, relative to the input order of events into the stats command.  chart , stats , timechart
 
last(X)
 This function returns the last seen value of the field X. In general, the last seen value of the field is the oldest instance of this field relative to the input order of events into the stats command.  chart , stats , timechart
 
latest(X)
 This function returns the chronologically latest seen occurrence of a value of a field X.  chart , stats , timechart
 
list(X)
 This function returns the list of all values of the field X as a multivalue entry. The order of the values reflects the order of input events.  chart , stats , timechart
 
max(X)
 This function returns the maximum value of the field X. If the values of X are nonnumeric, the max is found from lexicographic ordering.  chart , stats , timechart , sparkline()
 This example returns the maximum value of "size":

mean(X)
 This function returns the arithmetic mean of the field X. See also, avg(X).  chart , stats , timechart , sparkline()
 This example returns the mean of "kbps" values:

median(X)
 This function returns the middlemost value of the field X.
Note: The median calculation is more correct for odd numbers of events. In cases where you have an even number of events, the median is approximated to be the higher of the two values.  chart , stats , timechart
 
min(X)
 This function returns the minimum value of the field X. If the values of X are nonnumeric, the min is found from lexicographic ordering.  chart , stats , timechart
 
mode(X)
 This function returns the most frequent value of the field X.  chart , stats , timechart
 
p<X>(Y)  perc<X>(Y)  exactperc<X>(Y)  upperperc<X>(Y)
 This function returns the Xth percentile value of the numeric field Y, where X is an integer between 1 and 99. The percentile Xth function sorts the values of Y in an increasing order. Then, if you consider that 0% is the lowest and 100% the highest, the functions picks the value that corresponds to the position of the X% value.
The functions perc, p, and upperperc give approximate values for the integer percentile requested. The approximation algorithm used provides a strict bound of the actual value for any percentile. The functions perc and p return a single number that represents the lower end of that range while upperperc gives the approximate upper bound. exactperc provides the exact value, but will be very expensive for high cardinality fields.  chart , stats , timechart
 For the list of values Y = {10,9,8,7,6,5,4,3,2,1} :

per_day(X)
 This function returns the values of field X per day.  timechart
 This example returns the values of "total" per day.

per_hour(X)
 This function returns the values of field X per hour.  timechart
 This example returns the values of "total" per hour.

per_minute(X)
 This function returns the values of field X per minute.  timechart
 This example returns the values of "total" per minute.

per_second(X)
 This function returns the values of field X per second.  timechart
 This example returns values of "kb" per second:

range(X)
 This function returns the difference between the max and min values of the field X ONLY IF the value of X are numeric.  chart , stats , timechart , sparkline()
 
stdev(X)
 This function returns the sample standard deviation of the field X.  chart , stats , timechart , sparkline()
 This example returns the standard deviation of wildcarded fields "*delay" which can apply to both, "delay" and "xdelay".

stdevp(X)
 This function returns the population standard deviation of the field X.  chart , stats , timechart , sparkline()
 
sum(X)
 This function returns the sum of the values of the field X.  chart , stats , timechart , sparkline()
 sum(eval(date_hour * date_minute))

sumsq(X)
 This function returns the sum of the squares of the values of the field X.  chart , stats , timechart , sparkline()
 
values(X)
 This function returns the list of all distinct values of the field X as a multivalue entry. The order of the values is lexicographical.  chart , stats , timechart
 
var(X)
 This function returns the sample variance of the field X.  chart , stats , timechart , sparkline()
 
varp(X)
 This function returns the population variance of the field X.  chart , stats , timechart , sparkline() .

This documentation applies to the following versions of Splunk: 5.0 , 5.0.1 , 5.0.2 , 5.0.3 , 5.0.4 , 5.0.5 , 5.0.6 , 5.0.7 , 5.0.8 , 5.0.9 , 6.0 , 6.0.1 , 6.0.2 , 6.0.3 , 6.0.4 , 6.0.5 , 6.1 , 6.1.1 , 6.1.2 View the Article History for its revisions.
Comments
Thanks for pointing that out, Yoho, we've corrected the errors.
Some words are missing in the description of "last" and "first". For "first", there is no verb in the second sentence. For "last", "is the oldest instance of this field" is missing
It would be nice to implement not only "first" and "last", but also "second", "third".... in order to identify different values of the same field, for example in a transaction.