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

PowerApps集合中统计各项目出现次数的方法求助

在PowerApps中统计Collection项目的累计出现次数

实现步骤

  1. 先将SharePoint列表Product的数据加载到Collection中:
ClearCollect(colProducts, Product);
  1. 生成带累计计数的结果Collection:
    如果你的列表默认使用ID排序,直接用以下公式:
ClearCollect(colFruitCounts, 
    AddColumns(
        colProducts,
        "Number of Occurrences",
        CountIf(
            FirstN(colProducts, ThisRecord.ID),
            Fruit = ThisRecord.Fruit
        )
    )
);

若需要按创建时间这类自定义顺序统计,先排序再计算:

// 先按创建时间升序排序数据
ClearCollect(colSortedProducts, Sort(Product, Created, Ascending));
// 生成计数结果
ClearCollect(colFruitCounts, 
    AddColumns(
        colSortedProducts,
        "Number of Occurrences",
        CountIf(
            FirstN(colSortedProducts, Index(colSortedProducts, ThisRecord)),
            Fruit = ThisRecord.Fruit
        )
    )
);

原理说明

  • FirstN函数提取当前行及之前的所有记录,确保只统计到当前位置的出现次数
  • CountIf函数在提取的记录中,统计和当前行Fruit字段值相同的条目数量,该数值就是对应水果到当前行的累计出现次数

之后用Gallery控件绑定colFruitCounts,添加两个标签分别显示ThisItem.Fruit和ThisItem.'Number of Occurrences',就能得到你想要的结果样式。

内容的提问来源于stack exchange,提问作者Kendall Outlaw

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 04:07:41