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

Excel中无需排序求累计占比达75%的临界值

解决方案:Excel中找到占总价值75%的最大数值集合临界值

单个公式实现(Excel 365/2021 动态数组版本)

假设数值存储在A2:A10区域,直接用以下公式返回临界值:

=LET(
    vals, A2:A10,
    total, SUM(vals),
    target, total*0.75,
    sorted_vals, SORT(vals,,-1),
    running_sum, SCAN(0, sorted_vals, LAMBDA(a,b,a+b)),
    first_over, XMATCH(TRUE, running_sum>=target,1),
    IF(first_over=1, sorted_vals[1], INDEX(sorted_vals, first_over-1))
)

公式逻辑:

  • 计算总价值及75%的目标阈值
  • 在内存中对数值降序排序(不改动原数据顺序)
  • 生成累计求和数组,定位第一个累计和≥阈值的位置
  • 返回累计到该位置前一个的数值(匹配你示例中累计占比67.7%时的750)

如果使用旧版Excel(无动态数组支持),可使用数组公式(需按Ctrl+Shift+Enter确认输入):

=INDEX(A2:A10,MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A10,0,0,ROW(A2:A10)-ROW(A2)+1))>=SUM(A2:A10)*0.75,0)-1)

VBA宏方案(兼容所有Excel版本)

如果需要更强的兼容性或自定义空间,添加以下自定义函数:

Function Find75PctThreshold(rng As Range) As Variant
    Dim arr() As Variant, total As Double, target As Double
    Dim runningSum As Double, temp As Double
    Dim i As Integer, j As Integer
    
    arr = rng.Value
    total = Application.Sum(rng)
    target = total * 0.75
    
    ' 内存中降序排序(冒泡法,不修改原数据)
    For i = LBound(arr, 1) To UBound(arr, 1) - 1
        For j = i + 1 To UBound(arr, 1)
            If arr(i, 1) < arr(j, 1) Then
                temp = arr(i, 1)
                arr(i, 1) = arr(j, 1)
                arr(j, 1) = temp
            End If
        Next j
    Next i
    
    ' 累加判断临界值
    runningSum = 0
    For i = LBound(arr, 1) To UBound(arr, 1)
        runningSum = runningSum + arr(i, 1)
        If runningSum >= target Then
            Find75PctThreshold = IIf(i = LBound(arr, 1), arr(i, 1), arr(i - 1, 1))
            Exit Function
        End If
    Next i
    Find75PctThreshold = arr(UBound(arr, 1), 1)
End Function

使用方式:

  1. 按Alt+F11打开VBA编辑器,插入模块并粘贴上述代码
  2. 在Excel单元格中输入=Find75PctThreshold(A2:A10)(替换为你的实际数值区域)即可得到结果

备注:

  • 所有方案均不会修改原数据的顺序,排序和计算仅在内存中完成
  • 若你需要的是刚好让累计超过75%的数值(而非累计未超时的最后一个),只需调整返回逻辑:公式中直接返回INDEX(sorted_vals, first_over),VBA中返回arr(i,1)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 10:40:49