power查询如何从文本文件中提取数据

时间:2015-11-12 13:21:35

标签: powerquery

我有一个文本文件 - 实际上是一个报告 - 有几个页面,每个页面都有一个页眉和一个页脚。标题有一个字符串,表示页面正文中涵盖的主题。我想提取与特定主题相关的页面主体。页眉和页脚具有相同数量的线条,并且主体具有与注释底部的示例中所示相同的结构。如何仅提取有关索赔类型BBB的信息? 报告顶部要跳过的行数未知,以及报告底部要删除的行数。有人能指出我正确的方向吗?谢谢。

call()

2 个答案:

答案 0 :(得分:0)

我认为没有办法纯粹通过UI完成这项工作。您需要使用Table.PositionOfList.PositionOf方法。

这就是我所拥有的:

let
    Source = Table // however you get the table
    #"Position of Claims" = Table.PositionOf(Source, [Column1 = "Claims type : BBB", Column2 = null]),
    // Remove entries above the table belonging to Claims type BBB.
    #"Remove Top Rows" = Table.Skip(Source, #"Position of Claims" + 2),
    // Check which column has the "End of Page" tag
    #"Added Custom" = Table.AddColumn(#"Remove Top Rows", "Custom", each if [Column1] is text and Text.StartsWith([Column1], "End of Page") then 1 else 0),
    #"Position of End of Page" = List.PositionOf(#"Added Custom"[Custom], 1),
    // Remove rows that don't belong to this page's table
    #"Remove Bottom Rows" = Table.FirstN(#"Added Custom", #"Position of End of Page"),
    // Remove the column that told us which row had End of Page on it
    #"Removed Columns" = Table.RemoveColumns(#"Remove Bottom Rows",{"Custom"})
in
    #"Removed Columns"`

答案 1 :(得分:0)

您只能使用UI执行此操作:

let
    Source= Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddCustom = Table.AddColumn(Source, "Custom", each if Text.Start([Column1],6)="Claims" then Text.End([Column1],3) else if Text.Start([Column1],6)="End of" then "Trash" else null),
    ReplErrs = Table.ReplaceErrorValues(AddCustom, {{"Custom", null}}),
    FillDown = Table.FillDown(ReplErrs,{"Custom"}),
    FilterBBB = Table.SelectRows(FillDown, each ([Custom] = "BBB")),
    Rem1st = Table.Skip(FilterBBB,1),
    Promoted = Table.PromoteHeaders(Rem1st)
in
    Promoted