Syntax
List.Positions(list as list) as list
About
返回指定输入列表的偏移量列表。
-
list:输入列表。
使用List.Transform更改列表时,可以使用位置列表来让变换访问这些位置。
示例 1
在列表中查找值偏移量 {1, 2, 3, 4, null, 5}。
用法
List.Positions({1, 2, 3, 4, null, 5})
输出
{0, 1, 2, 3, 4, 5}
示例 2
创建一个表,该表根据客户在列表中的位置为每个客户分配 ID。
用法
let
customers = {"Alice", "Bob", "Charlie", "Diana"},
resultTable =
Table.FromRecords(
List.Transform(
List.Positions(customers),
each [
IDNumber = _ + 1, // Make it 1-based
CustomerName = customers{_}
]
),
type table [IDNumber = Int64.Type, CustomerName = text]
)
in
resultTable
输出
#table (type table[IDNumber = Int64.Type, CustomerName = text],
{
{1, "Alice"},
{2, "Bob"},
{3, "Charlie"},
{4, "Diana"}
})