Cypher percentileDisc Function

percentileDisc() returns the percentile of the given value over a group, with a percentile from 0.0 to 1.0. It uses a rounding method and calculates the nearest value to the percentile. For interpolated values, see percentileCont.

Syntax:percentileDisc(expression, percentile)

Returns: Either an Integer or a Float, depending on the values returned by expression and whether or not the calculation overflows.

Arguments

NameDescription
expressionA numeric expression.
percentileA numeric value between 0.0 and 1.0

Example

MATCH (a:Person)
RETURN percentileDisc(a.salary, 0.3)

The 30th percentile of the values in the property salary is returned for the node Person. In this case, 0.3 is the median, or 30th percentile. For example, the result might be 42,461

Considerations

  • All null values are excluded from the calculation.
  • percentileDisc(null, percentile) returns null.
  • percentileDisc(null, null) returns an Error.

Example

MATCH (a:Student)
RETURN percentileDisc(a.marks, 0.8)

The above query will return the 80th percentile of the values in the property marks for the nodes with the label Student. The result for a given set of data is, for example-

percentileDisc(a.marks, 0.8)
84

Example

CREATE (a:Person {age:10}), (b:Person {age:15}), (c:Person {age:20}), (d:Person {age:25})
WITH a, b, c, d
MATCH (p:Person)
RETURN percentileDisc(p.age, 0.75)

The above query will return the 75th percentile of the values in the property age for all the nodes with the label Person. The result returned will be-

percentileDisc(p.age, 0.75)
20

Example

CREATE (a:Person {age:10}), (b:Person {age:null}), (c:Person {age:20}), (d:Person {age:null})
WITH a, b, c, d
MATCH (p:Person)
RETURN percentileDisc(p.age, 0.5)

The above query will return the 50th percentile of the values in the property age for all the nodes with the label Person. It will be calculated with a weighted average. The result returned will be-

percentileDisc(p.age, 0.5)
10

NotepercentileDisc() will ignore all the null values from its calculation.

Example

RETURN percentileDisc(null, 0.3)

Returns the following Result

percentileDisc(null, 0.3)
null

NotepercentileDisc(null, percentile) will return null.

Example

RETURN percentileDisc(null, null)

Returns the following Result

percentileDisc(null, null)
ERROR Neo.ClientError.Statement.SyntaxError

NotepercentileDisc(null, null) will return Error.

Learn More