powerquery m语言 - 如何选择所有行直到值

时间:2016-12-08 13:52:21

标签: powerquery m

this one非常相似但使用Power Query / M

的问题

鉴于以下内容(Power Query Excel导入)......

    A       B
1   Item    Amount
2   Item1   1
3   Item2   4
4   Grand   5

如何用Grand选择所有行直到(排除)第四行? (并排除之后的所有行)

我创建了一个像这样的新列:

#"Added Custom" = Table.AddColumn(#"Changed Type1", "match_check", each Text.Contains([A],"Grand"))

它正确表示" Grand"但是,真正需要的是它前面的所有行(并且它之后没有任何行)。

1 个答案:

答案 0 :(得分:1)

这很简单! :))

继续你的代码:

#"Added Custom" = Table.AddColumn(#"Changed Type1", "match_check", each Text.Contains([A],"Grand")), //Your line

AddIndex = Table.AddIndexColumn(#"Added Custom", 1, 1),
SelectGrandTotals = Table.SelectRows(AddIndex, each [match_check] = true), //select matched rows with grand totals
MinIndex = List.Min(SelectGrandTotals[Index]), //select first totals row index (if there are several such rows)
FilterTable = Table.SelectRows(AddIndex, each [Index] < MinIndex) //get all rows before