2015-11-12 58 views
1

我有一个文本文件 - 实际上是一个报告 - 有几个页面,每个页面都有一个页眉和一个页脚。标题包含一个字符串,指示页面正文中涵盖的主题。我想提取与特定主题相关的页面主体。页眉和页脚具有相同的行数,并且主体具有与笔记底部示例中所示相同的结构。如何仅提取有关理赔类型BBB的信息? 要在报告顶部跳过的行数未知,以及要在报告底部放置的行数。有人能指出我正确的方向吗?谢谢。电力查询如何从文本文件中提取数据

Page 1 
Claims type: AAA 
Claim #    Amount $ 
11111    10 
11112    20 
..... 
End of Page 1 
Page 2 
Claims type : AAA 
...etc. 
End of Page 2   
Page 3 
Claims type : BBB 
Claim #    Amount $ 
21111    100 
21112    200 
..... 
End of Page 3 
Page 4 
Claims type : CCC 

回答

0

我不认为有一种方法可以纯粹通过用户界面。您需要使用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"` 
+0

谢谢亚历杭德罗。在删除底行的步骤中有一个Expression.Error,它表示:我们期望一个CountOrCondition值。 – DP17000

+0

对不起,包含页脚的大小作为Remove Bottom Rows的最后一个参数。 –

+0

这一次它运行。我有一些其他问题(如它不会找到索赔类型...),但我想这是由于我正在阅读的文本文件。这对我有很大的帮助 - 谢谢Alejandro。 – DP17000

0

你可以用唯一的用户界面做到这一点:

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 
+0

最大,谢谢。这适用于我...我是一名新生,我可以看到你在博士后部分...我仍然有工作要做。 – DP17000

+0

@ DP17000对不评论代码抱歉:1)在“each”之后添加第二行中带有公式的自定义列; 2)用空值替换新列中的错误3)填写新列4)过滤你需要的(“BBB”); 5)删除第一行; 5)宣传标题。这一切都可以用UI完成,除了第一行的公式:) –

相关问题