Table.AddIndexColumn
Sintaxis
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
Acerca de
Anexa una columna denominada newColumnName
a table
con valores de posición explícitos. Un valor opcional, initialValue
, especifica el valor inicial del índice. Un valor opcional, increment
, especifica el incremento que se aplicará a cada valor de índice.
Ejemplo 1
Agregar a la tabla una columna de índice denominada "Index".
Uso
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"
)
Salida
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]
})
Ejemplo 2
Agregar a la tabla una columna de índice denominada "Index" que empiece en el valor 10 y vaya incrementando ese valor en 5.
Uso
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
)
Salida
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]
})