吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1585|回复: 3
收起左侧

[求助] Power Query(M语言),删除重复项,如何实现保留最后一行

[复制链接]
cqwcns 发表于 2022-11-19 15:52
本帖最后由 cqwcns 于 2022-11-19 16:00 编辑

我发现power query删除重复项,默认是保留第一行的,而我希望保留最后一行。
我尝试先降序(日期列),再删除重复项,发现排序步骤对删除重复项是没有效果的。
以下代码,虽然操作了降序,但删除重复项仍是保留day1的。
[HTML] 纯文本查看 复制代码
let
    源 = Table.FromRecords({
    [day = 1, Name = "Bob", Phone = "123-4567"],
    [day = 1, Name = "Jim", Phone = "987-6543"],
    [day = 1, Name = "Paul", Phone = "543-7890"],
    [day = 1, Name = "Bob", Phone = "123-4567"],
    [day = 1, Name = "Jim", Phone = "987-6543"],
    [day = 2, Name = "Paul", Phone = "543-7890"],
    [day = 2, Name = "Bob", Phone = "123-4567"],
    [day = 2, Name = "Jim", Phone = "987-6543"],
    [day = 2, Name = "Paul", Phone = "543-7890"],
    [day = 2, Name = "Bob", Phone = "123-4567"],
    [day = 2, Name = "Jim", Phone = "987-6543"],
    [day = 3, Name = "Paul", Phone = "543-7890"],
    [day = 3, Name = "Bob", Phone = "123-4567"],
    [day = 5, Name = "Jim", Phone = "987-6543"],
    [day = 6, Name = "Paul", Phone = "543-7890"],
    [day = 6, Name = "Bob", Phone = "123-4567"],
    [day = 6, Name = "Jim", Phone = "987-6543"],
    [day = 6, Name = "Paul", Phone = "543-7890"]
    }),
    排序的行 = Table.Sort(源,{{"day", Order.Descending}}),
    删除的副本 = Table.Distinct(排序的行, {"Name"})
in
    删除的副本


所以,一般这种需求如何实现?
请大佬指教,感谢。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

放羊的狼 发表于 2022-11-19 16:02
价格buff试试

免费评分

参与人数 1热心值 +1 收起 理由
cqwcns + 1 谢谢@Thanks!

查看全部评分

放羊的狼 发表于 2022-11-19 16:10
试了一下,加了buffer可以达到你的要求
[C] 纯文本查看 复制代码
let
    源 = Table.FromRecords({
    [day = 1, Name = "Bob", Phone = "123-4567"],
    [day = 1, Name = "Jim", Phone = "987-6543"],
    [day = 1, Name = "Paul", Phone = "543-7890"],
    [day = 1, Name = "Bob", Phone = "123-4567"],
    [day = 1, Name = "Jim", Phone = "987-6543"],
    [day = 2, Name = "Paul", Phone = "543-7890"],
    [day = 2, Name = "Bob", Phone = "123-4567"],
    [day = 2, Name = "Jim", Phone = "987-6543"],
    [day = 2, Name = "Paul", Phone = "543-7890"],
    [day = 2, Name = "Bob", Phone = "123-4567"],
    [day = 2, Name = "Jim", Phone = "987-6543"],
    [day = 3, Name = "Paul", Phone = "543-7890"],
    [day = 3, Name = "Bob", Phone = "123-4567"],
    [day = 5, Name = "Jim", Phone = "987-6543"],
    [day = 6, Name = "Paul", Phone = "543-7890"],
    [day = 6, Name = "Bob", Phone = "123-4567"],
    [day = 6, Name = "Jim", Phone = "987-6543"],
    [day = 6, Name = "Paul", Phone = "543-7890"]
    }),
    排序的行 = Table.Buffer(Table.Sort(源,{{"day", Order.Descending}})),
    删除的副本 = Table.Distinct(排序的行, {"Name"})
in
    删除的副本

免费评分

参与人数 1热心值 +1 收起 理由
cqwcns + 1 谢谢@Thanks!

查看全部评分

50lovelace 发表于 2022-11-19 21:16
排序了后面加一步:添加索引列  再删除就可以了

免费评分

参与人数 1热心值 +1 收起 理由
cqwcns + 1 谢谢@Thanks!

查看全部评分

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 07:10

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表