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
MEDIAN formula in Excel - practical examplesMEDIAN formula in Excel - practical examplesApr 11, 2025 pm 12:08 PM

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Google Spreadsheet COUNTIF function with formula examplesGoogle Spreadsheet COUNTIF function with formula examplesApr 11, 2025 pm 12:03 PM

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

Excel shared workbook: How to share Excel file for multiple usersExcel shared workbook: How to share Excel file for multiple usersApr 11, 2025 am 11:58 AM

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

How to convert Excel to JPG - save .xls or .xlsx as image fileHow to convert Excel to JPG - save .xls or .xlsx as image fileApr 11, 2025 am 11:31 AM

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

Excel names and named ranges: how to define and use in formulasExcel names and named ranges: how to define and use in formulasApr 11, 2025 am 11:13 AM

This tutorial clarifies the function of Excel names and demonstrates how to define names for cells, ranges, constants, or formulas. It also covers editing, filtering, and deleting defined names. Excel names, while incredibly useful, are often overlo

Standard deviation Excel: functions and formula examplesStandard deviation Excel: functions and formula examplesApr 11, 2025 am 11:01 AM

This tutorial clarifies the distinction between standard deviation and standard error of the mean, guiding you on the optimal Excel functions for standard deviation calculations. In descriptive statistics, the mean and standard deviation are intrinsi

Square root in Excel: SQRT function and other waysSquare root in Excel: SQRT function and other waysApr 11, 2025 am 10:34 AM

This Excel tutorial demonstrates how to calculate square roots and nth roots. Finding the square root is a common mathematical operation, and Excel offers several methods. Methods for Calculating Square Roots in Excel: Using the SQRT Function: The

Google Sheets basics: Learn how to work with Google SpreadsheetsGoogle Sheets basics: Learn how to work with Google SpreadsheetsApr 11, 2025 am 10:23 AM

Unlock the Power of Google Sheets: A Beginner's Guide This tutorial introduces the fundamentals of Google Sheets, a powerful and versatile alternative to MS Excel. Learn how to effortlessly manage spreadsheets, leverage key features, and collaborate

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool