【问题标题】:Excel Powerquery split table top / bottom 50 percentExcel Power Query 拆分表格顶部/底部 50%
【发布时间】:2018-06-22 08:21:26
【问题描述】:

我在 Excel 中有一个示例表来说明我的问题。 两列(名字、姓氏)、11 行和一个标题行。 我想将 get&transform (powerquery) 链接到同一个工作簿中的另一个工作表,我希望在其中有两个表 A 和 B 具有相同的结构作为源表。我希望 A 显示第 1-6 行,B 显示第 7-11 行。
但是:我希望这种拆分是动态的。所以我希望 A 显示前 50% 的四舍五入,而 B 显示其余的。我已经看到了前 N 行,并阅读了一些关于在不同的 powerquery 中计数和使用 Filedropper Excel file where image below comes from

的帖子

【问题讨论】:

    标签: excel powerquery


    【解决方案1】:

    上半场:

    let
        Source = Excel.CurrentWorkbook(){[Name="SourceTable"]}[Content],
        TopHalfRows = Number.RoundUp(Table.RowCount(Source) / 2),
        KeepTopHalf = Table.FirstN(Source, TopHalfRows)
    in
        KeepTopHalf
    

    下半场:

    let
        Source = Excel.CurrentWorkbook(){[Name="SourceTable"]}[Content],
        TopHalfRows = Number.RoundUp(Table.RowCount(Source) / 2),
        DeleteTopHalf = Table.Skip(Source, TopHalfRows)
    in
        DeleteTopHalf
    

    编辑:

    这显示了如何在拆分之前通过添加过滤步骤进行修改:

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([firstname], "Ab")),
        TopHalfRows = Number.RoundUp(Table.RowCount(#"Filtered Rows") / 2),
        KeepTopHalf = Table.FirstN(#"Filtered Rows", TopHalfRows)
    in
        KeepTopHalf
    

    【讨论】:

    • 这太棒了!我有一个后续问题。我可以添加一个过滤器到:Source = Excel.CurrentWorkbook(){[Name="SourceTable"]}[Content],例如,只使用以 'ab' 开头的名字吗?
    • 我不知道怎么做。我想在计数之前过滤。所以它必须过滤 SourceTable 。
    • 在 Source 步骤之后插入过滤器步骤,然后在以下行中引用该过滤器步骤而不是 Source。
    • 我已经编辑了答案以显示在拆分前应用过滤器的示例。
    • Olly 找到了,非常感谢。我在过滤源之间添加了一条线,使用过滤后的结果。好东西。非常感谢!
    猜你喜欢
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2011-12-30
    相关资源
    最近更新 更多