You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerApps技术问询:如何从SharePoint列表获取满足指定条件的最新记录?

如何在PowerApps中获取SharePoint列表里符合特定条件的最新记录

当然可以实现!你推测的思路完全正确——通过排序后选取第一条的方式就能轻松拿到符合条件的最新记录,下面给你详细的实现方法和注意事项:

核心实现逻辑

先筛选出满足条件的记录集,再按日期列(或唯一递增列)降序排序(让最新的记录排在最前面),最后取排序后的第一条记录即可。

具体公式示例

假设你的SharePoint列表名为Applications,状态列是Status,日期列用SharePoint默认的Created(记录创建时间),那么获取最新Pending状态记录的公式如下:

First(Sort(Filter(Applications, Status = "Pending"), Created, Descending))

公式拆解:

  • Filter(Applications, Status = "Pending"):先筛选出所有状态为"Pending"的记录
  • Sort(..., Created, Descending):将筛选后的记录按Created日期从新到旧排序
  • First(...):提取排序后的第一条记录,也就是最新的那条

获取记录的指定字段

如果需要直接获取这条最新记录的某个字段(比如标题Title),可以在公式末尾加上字段名:

First(Sort(Filter(Applications, Status = "Pending"), Created, Descending)).Title

更稳妥的排序方式(避免同时间记录的歧义)

如果存在多条记录在同一时间创建的情况,用Created排序可能无法精准定位到最新的那条。此时可以改用SharePoint的ID列排序(ID是自动递增的,最新记录的ID最大),公式如下:

First(Sort(Filter(Applications, Status = "Pending"), ID, Descending))

结合CountIf避免空值错误

你已经会用CountIf(Applications, Status = "Pending")统计符合条件的记录数,可以把它和获取最新记录的逻辑结合,避免当没有Pending记录时出现错误:

If(
    CountIf(Applications, Status = "Pending") > 0,
    First(Sort(Filter(Applications, Status = "Pending"), ID, Descending)).Title,
    "暂无待处理申请"
)

内容的提问来源于stack exchange,提问作者Perry J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:24:21