search
HomeTopicsexcelLet's analyze how Excel uses functions to find combinations that sum to a certain value.

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了如何使用函数寻找总和为某个值的组合的问题,下面就来看一下,希望对大家有帮助。

Let's analyze how Excel uses functions to find combinations that sum to a certain value.

相关学习推荐:excel教程

今天给大家分享一下如何使用函数寻找总和为某个值的组合。

举个例子。

如下图所示,A~B列是数据源,A列是发票号,B列是发票金额。现在需要寻找总和为F1单元格指定值,比如20,089的发票组合。

Lets analyze how Excel uses functions to find combinations that sum to a certain value.

关于这个问题,很久以前给大家分享过规划求解的方法;今天再给大家分享一下函数的方法。

在C2单元格输入以下公式,并复制到C2:C21区域。

=IF(SUM(C$2:C$21)=F$1,C2,B2*RANDBETWEEN(0,1))

公式输入后系统会提示循环引用,这是由于公式引用了公式所在单元格的值,不过别管他,谁稀罕爱她。

依次点击Excel左上角的「文件」→「选项」命令,打开文件选项对话框,切换到「公式」选项卡,选中「启动迭代计算」复选框,将「最多迭代次数」设置为30000。「确定」后关闭对话框。

Lets analyze how Excel uses functions to find combinations that sum to a certain value.

此时C列公式会自动重算,重算结果非0的项即为发票组合。可以在F2单元格输入一个SUM函数公式进行验证。

Lets analyze how Excel uses functions to find combinations that sum to a certain value.

给大家解释一下公式的意思。

=IF(SUM(C$2:C$21)=F$1,C2,B2*RANDBETWEEN(0,1))

公式首先判断C2:C21区域的总和是否等于F1单元格指定的目标值,如果相等,则返回C2自身的值,否则,返回B2单元格发票金额乘以0或1。当乘以0时,结果返回0,表示该发票金额未被选中,当乘以1时,返回发票金额自身,表示被选中。

由于公式引用了公式所在单元格的值,比如C2单元格的公式SUM(C$2:C$21),也就会触发循环引用。此时我们启用迭代计算,系统会反复计算该公式,直至停止迭代的条件成立(C2:C21的总和等于目标值),或迭代次数用尽。

就这么回事。

最后留个练习题。

Lets analyze how Excel uses functions to find combinations that sum to a certain value.

如上图所示,已知总和25,由10个数值构成,每个数值大于等于1,且小于等于5,请列出这10个数值的任一组合。

参考答案:

A3:A12输入公式 

=IF(SUM(A$3:A$12)=B$1,A3,RANDBETWEEN(1,5))

相关学习推荐:excel教程

The above is the detailed content of Let's analyze how Excel uses functions to find combinations that sum to a certain value.. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel Home. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment