SAMPLEAXISWITHLOCALMINMAX
A line chart's sample of a table: each bin's least and greatest values per series; past the size asked, Power BI Desktop's own bins may differ.
Group: Window and visual calculations. Compatible with DAX.
Syntax
SAMPLEAXISWITHLOCALMINMAX ( <Size>, <Table>, <Axis>, <Measure> [, <Measure>] …, <MinResolution> [, <DynamicSeries>] … [, <DynamicSeriesSelectionCriteria>] [, <DynamicSeriesSelectionOrder>] [, <MaxResolution>] [, <MaxDynamicSeries>] [, <MaxIterations>] )
| Parameter | Type | Description |
|---|---|---|
Size | Whole number | About how many rows to keep. |
Table | Table | The chart's points: one row per point. |
Axis | Column | The column along the chart's horizontal axis: numbers or dates. |
Measure | Column repeatable | A column of the values drawn: the sample keeps the rows with each bin's smallest and largest value. |
MinResolution | Whole number | The fewest points to keep for each series across the axis. |
DynamicSeries | Column optional, repeatable | Columns that make the series, one line each. |
DynamicSeriesSelectionCriteria | Keyword optional | NONE or ALPHABETICAL: the order of the series when not all of them fit. |
DynamicSeriesSelectionOrder | Keyword optional | ASC or DESC for that order. |
MaxResolution | Whole number optional | The most points to keep for each series. |
MaxDynamicSeries | Whole number optional | How many series to keep at most. |
MaxIterations | Whole number optional | How many tries at a bin width that brings the rows near Size. |
Returns
Table. Rows of the table, in its own order: all of them, or a sample that keeps each bin's lowest and highest points.
Remarks
- Power BI's line charts use it to thin out a long series of points without losing its peaks and dips. Report authors seldom write it by hand.
- When the table has no more rows than Size, it comes back whole; a Size of 0 or less gives an empty table.
- Otherwise the axis is cut into bins of equal width, and for each series the rows holding a bin's lowest and highest value are kept; the number of bins is tried until the rows come near Size.
- Rows whose axis value is blank are left out of a sample.
Compared with DAX
Past Size rows, OpenBI's bins are its own: Power BI may keep other rows of the same table. Up to Size rows, both return the table whole.
Examples
Few enough rows: the whole table
EVALUATE
VAR Days =
DATATABLE (
"Day", INTEGER, "Liters", INTEGER,
{ { 1, 40 }, { 2, 55 }, { 3, 38 }, { 4, 61 }, { 5, 70 }, { 6, 52 }, { 7, 45 }, { 8, 66 } }
)
RETURN
SAMPLEAXISWITHLOCALMINMAX ( 10, Days, [Day], [Liters], 10 )
ORDER BY [Day]
| Day | Liters |
|---|---|
| 1 | 40 |
| 2 | 55 |
| 3 | 38 |
| 4 | 61 |
| 5 | 70 |
| 6 | 52 |
| 7 | 45 |
| 8 | 66 |
Eight days thinned to four
Two bins, days 1 to 4 and 5 to 8: each keeps its lowest and its highest day.
EVALUATE
VAR Days =
DATATABLE (
"Day", INTEGER, "Liters", INTEGER,
{ { 1, 40 }, { 2, 55 }, { 3, 38 }, { 4, 61 }, { 5, 70 }, { 6, 52 }, { 7, 45 }, { 8, 66 } }
)
RETURN
SAMPLEAXISWITHLOCALMINMAX ( 4, Days, [Day], [Liters], 4 )
ORDER BY [Day]
| Day | Liters |
|---|---|
| 3 | 38 |
| 4 | 61 |
| 5 | 70 |
| 7 | 45 |
Days 3 and 4 are the first bin's low and high, days 7 and 5 the second's.