Table.AddIndexColumn
構文
Table.AddIndexColumn(table as table, newColumnName as text, optional initialValue as nullable number, optional increment as nullable number, optional columnType as nullable type) as table
バージョン情報
newColumnName
という名前の列を、明示的な位置の値を含む table
に追加します。 省略可能な値 (initialValue
) は、インデックスの初期値です。 省略可能な値 increment
では、各インデックス値の増加量を指定します。
例 1
"Index" という名前のインデックス列をテーブルに追加します。
使用方法
Table.AddIndexColumn(
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
}),
"Index"
)
出力
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567", Index = 0],
[CustomerID = 2, Name = "Jim", Phone = "987-6543", Index = 1],
[CustomerID = 3, Name = "Paul", Phone = "543-7890", Index = 2],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550", Index = 3]
})
例 2
値 10 から開始し、5 ずつ増加する "index" という名前のインデックス列をテーブルに追加します。
使用方法
Table.AddIndexColumn(
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
}),
"Index",
10,
5
)
出力
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567", Index = 10],
[CustomerID = 2, Name = "Jim", Phone = "987-6543", Index = 15],
[CustomerID = 3, Name = "Paul", Phone = "543-7890", Index = 20],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550", Index = 25]
})