1

与此问题非常相似,但使用 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”行,但真正需要的是它前面的所有行(而不是它后面的所有行)。

4

1 回答 1

2

这很容易!:))

继续你的代码:

#"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
于 2016-12-08T15:28:48.180 回答