Compartir a través de


range operator

Applies to: ✅Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Genera una tabla de valores de una columna única.

Note

Este operador no toma una entrada tabular.

Syntax

range columnNamefromstarttostopstepstep

Learn more about syntax conventions.

Parameters

Name Type Required Description
columnName string ✔️ Nombre de la sola columna de la tabla de salida.
start int, long, real, datetime o timespan ✔️ Valor más pequeño de la salida.
stop int, long, real, datetime o timespan ✔️ The highest value being generated in the output or a bound on the highest value if step is over this value.
step int, long, real, datetime o timespan ✔️ Diferencia entre dos valores consecutivos.

Note

Los valores no pueden hacer referencia a las columnas de ninguna tabla. If you want to compute the range based on an input table, use the range function potentially with the mv-expand operator.

Returns

A table with a single column called columnName, whose values are start, start+step, ... up to and until stop.

Examples

En el ejemplo de esta sección se muestra cómo usar la sintaxis para ayudarle a empezar.

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

The examples in this article use publicly available tables, such as the Weather table in the Weather analytics sample gallery. Es posible que tenga que modificar el nombre de la tabla en la consulta de ejemplo para que coincida con la tabla del área de trabajo.

Intervalo en los últimos siete días

En el ejemplo siguiente se crea una tabla con entradas para la marca de tiempo actual extendida durante los últimos siete días, una vez al día.

range LastWeek from ago(7d) to now() step 1d

Output

LastWeek
2015-12-05 09:10:04.627
2015-12-06 09:10:04.627
...
2015-12-12 09:10:04.627

Combinar diferentes tiempos de detención

En el ejemplo siguiente se muestra cómo ampliar los intervalos para usar varias veces de detención mediante el operador union.

let Range1 = range Time from datetime(2024-01-01) to datetime(2024-01-05) step 1d;
let Range2 = range Time from datetime(2024-01-06) to datetime(2024-01-10) step 1d;
union Range1, Range2
| order by Time asc

Output

Time
2024-01-04 00:00:00.0000000
2024-01-05 00:00:00.0000000
2024-01-06 00:00:00.0000000
2024-01-07 00:00:00.0000000
2024-01-08 00:00:00.0000000
2024-01-09 00:00:00.0000000
2024-01-10 00:00:00.0000000

Intervalo mediante parámetros

En el ejemplo siguiente se muestra cómo usar el range operador con parámetros, que se extienden y consumen como una tabla.

let toUnixTime = (dt:datetime) 
{ 
    (dt - datetime(1970-01-01)) / 1s 
};
let MyMonthStart = startofmonth(now()); //Start of month
let StepBy = 4.534h; //Supported timespans
let nn = 64000; // Row Count parametrized
let MyTimeline = range MyMonthHour from MyMonthStart to now() step StepBy
| extend MyMonthHourinUnixTime = toUnixTime(MyMonthHour), DateOnly = bin(MyMonthHour,1d), TimeOnly = MyMonthHour - bin(MyMonthHour,1d)
; MyTimeline | order by MyMonthHour asc | take nn

Output

MyMonthHour MyMonthHourinUnixTime DateOnly TimeOnly
2023-02-01 00:00:00.0000000 1675209600 2023-02-01 00:00:00.0000000
2023-02-01 04:32:02.4000000 1675225922.4 2023-02-01 00:00:00.0000000
2023-02-01 09:04:04.8000000 1675242244.8 2023-02-01 00:00:00.0000000
2023-02-01 13:36:07.2000000 1675258567.2 2023-02-01 00:00:00.0000000
... ... ... ...

Incremented steps

En el ejemplo siguiente se crea una tabla con una sola columna denominada Steps cuyo tipo es long y se generan valores de uno a ocho incrementos en tres.

range Steps from 1 to 8 step 3

Output

Steps
1
4
7

Seguimientos a lo largo de un intervalo de tiempo

En el ejemplo siguiente se muestra cómo se puede usar el operador range para crear una tabla de dimensiones que se usa para introducir ceros donde los datos de origen no tienen valores. Toma marcas de tiempo de las últimas cuatro horas y cuenta los seguimientos de cada intervalo de un minuto. Cuando no hay seguimientos para un intervalo específico, el recuento es cero.

range TIMESTAMP from ago(4h) to now() step 1m
| join kind=fullouter
  (Traces
      | where TIMESTAMP > ago(4h)
      | summarize Count=count() by bin(TIMESTAMP, 1m)
  ) on TIMESTAMP
| project Count=iff(isnull(Count), 0, Count), TIMESTAMP
| render timechart