適用対象: ✅Microsoft Fabric✅Azure データ エクスプローラー✅Azure Monitor✅Microsoft Sentinel
値を切り捨てて、指定された bin サイズの倍数である整数にします。
多くの場合、summarize by ... と組み合わせて使用します。
値のセットが分散している場合に、特定の値ごとの小さなセットにグループ化されます。
bin()関数とfloor()関数は同等です
構文
              bin(
              value,roundTo)
構文規則について詳しく知る。
パラメーター
| 件名 | タイプ | 必須 | 説明 | 
|---|---|---|---|
| 価値 | int、long、real、 timespan、または datetime | ✔️ | 切り捨てする値。 | 
| roundTo | int、long、real、または timespan | ✔️ | valueを除算する "bin size"。 | 
返品
value 未満で、roundTo の最も近い倍数。 Null 値、ビン サイズが null、またはビン サイズが負の場合、結果は null になります。
例
次の例は、数値データを含む bin() 関数を示しています。
print bin(4.5, 1)
出力
| print_0 | 
|---|
| 4 | 
次の例では、タイムスパン データを含む bin() 関数を示します。
print bin(time(16d), 7d)
出力
| print_0 | 
|---|
| 14:00:00:00 | 
次の例は、datetime データを含む bin() 関数を示しています。
print bin(datetime(1970-05-11 13:45:07), 1d)
出力
| print_0 | 
|---|
| 1970-05-11T00:00:00Z | 
テーブルに対応する行がないビンの行がある場合は、テーブルにそれらのビンを埋め込することをお勧めします。次のクエリでは、4 月の 1 週間のカリフォルニアの強風雨イベントを調べます。 ただし、一部の日にはイベントはありません。
let Start = datetime('2007-04-07');
let End = Start + 7d;
StormEvents
| where StartTime between (Start .. End)
| where State == "CALIFORNIA" and EventType == "Strong Wind"
| summarize PropertyDamage=sum(DamageProperty) by bin(StartTime, 1d)
出力
| 開始時間 | PropertyDamage | 
|---|---|
| 2007-04-08T00:00:00Z | 3000 | 
| 2007-04-11T00:00:00Z | 1000 | 
| 2007-04-12T00:00:00Z | 105000 | 
1 週間を表すために、次のクエリでは、不足している日の結果テーブルに null 値が埋め込まれます。 プロセスの詳細な説明を次に示します。
- 
              union演算子を使用して、テーブルに行を追加します。
- 
              range演算子により、1 つの行と列を含むテーブルが生成されます。
- 
              mv-expand関数に対するrange演算子は、StartTimeとEndTimeの間にビンがある数の行を作成します。
- 
              PropertyDamageには0を使用します。
- 
              summarize演算子は、元のテーブルのビンを、union式によって生成されたテーブルにグループ化します。 このプロセスにより、出力には、ビンごとに 0 個または元の数の値を持つ 1 つの行が含まれるようになります。
let Start = datetime('2007-04-07');
let End = Start + 7d;
StormEvents
| where StartTime between (Start .. End)
| where State == "CALIFORNIA" and EventType == "Strong Wind"
| union (
    range x from 1 to 1 step 1
    | mv-expand StartTime=range(Start, End, 1d) to typeof(datetime)
    | extend PropertyDamage=0
    )
| summarize PropertyDamage=sum(DamageProperty) by bin(StartTime, 1d)
出力
| 開始時間 | PropertyDamage | 
|---|---|
| 2007-04-07T00:00:00Z | 0 | 
| 2007-04-08T00:00:00Z | 3000 | 
| 2007-04-09T00:00:00Z | 0 | 
| 2007-04-10T00:00:00Z | 0 | 
| 2007-04-11T00:00:00Z | 1000 | 
| 2007-04-12T00:00:00Z | 105000 | 
| 2007-04-13T00:00:00Z | 0 | 
| 2007-04-14T00:00:00Z | 0 |