OpenBI Docs Buy

HISTOGRAM OpenBI

Sorts an expression's values into bins and counts them, one row a bin: at round break points by default, or into a given number of bins of equal width.

Group: Statistics. OpenBI’s own: DAX has no function of this name.

Syntax

HISTOGRAM ( <table>, <value> [, <bins>] )
ParameterTypeDescription
tableTableThe rows to count.
valueExpression
evaluated for each row
The number worked out for each row.
binsWhole number
optional
How many bins of equal width, 1 or more. Left out, the bins are chosen for you.

Returns

Table. A row a bin, in order: Bin start, Bin end, Count, and Share (the bin's count over all the values counted).

Remarks

  • Without bins, the bins are R's hist: the number aimed at is Sturges', 1 + log2 n rounded up for n values, and the break points are round numbers as R's pretty picks them: steps such as 0.5, 1, 2, 5, 10 or 20.
  • With bins, the range from the smallest value to the largest is cut into that many equal parts.
  • A bin counts the values above its start up to its end, its end included; the first bin includes its start too.
  • Empty bins are rows with a count of 0, so the bins follow on without gaps.
  • Blank results are left out. When every value is the same, there is one bin, 1 wide, around it.

Compared with DAX

An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.

Examples

Ten delivery times

For ten values Sturges' rule aims at five bins; the round step R picks is 5 minutes, and seven bins of it cover 12 to 45, from 10. Both 15s fall in the first bin, as its end. R's hist(c(12, 14, 15, 15, 16, 18, 19, 21, 22, 45)) gives the same breaks and counts.

EVALUATE
VAR Times =
    DATATABLE (
        "Minutes", INTEGER,
        { { 12 }, { 14 }, { 15 }, { 15 }, { 16 }, { 18 }, { 19 }, { 21 }, { 22 }, { 45 } }
    )
RETURN
    HISTOGRAM ( Times, [Minutes] )
Bin startBin endCountShare
101540.4
152030.3
202520.2
253000
303500
354000
404510.1

Three bins of equal width

EVALUATE
VAR Times =
    DATATABLE (
        "Minutes", INTEGER,
        { { 12 }, { 14 }, { 15 }, { 15 }, { 16 }, { 18 }, { 19 }, { 21 }, { 22 }, { 45 } }
    )
RETURN
    HISTOGRAM ( Times, [Minutes], 3 )
Bin startBin endCountShare
122390.9
233400
344510.1

Months by liters sold

EVALUATE
HISTOGRAM ( VALUES ( Sales[Month] ), [Liters sold] )
Bin startBin endCountShare
4000045000100.277777777777778
4500050000130.361111111111111
500005500040.111111111111111
550006000050.138888888888889
600006500030.0833333333333333
650007000010.0277777777777778

DENSITY, BOXPLOT, PERCENTILE.INC, COUNTROWS.

Last updated · OpenBI Studio 0.3.74