search
HomeTopicsexcelHow to find combinations whose sum is a certain value in Excel

This article brings you relevant knowledge about excel. It mainly introduces the problem of how to use functions to find combinations that sum to a certain value. Let’s take a look at it together. I hope it will help Everyone is helpful.

How to find combinations whose sum is a certain value in Excel

Related learning recommendations: excel tutorial

Today I will share with you how to use a function to find a combination that sums to a certain value.

Let me give you an example.

As shown in the figure below, columns A~B are data sources, column A is the invoice number, and column B is the invoice amount. Now you need to find the sum of the invoice combinations specified in cell F1, such as 20,089.

How to find combinations whose sum is a certain value in Excel

Regarding this issue, I shared with you the planning solution method a long time ago; today I will share with you the function method.

Enter the following formula in cell C2 and copy it to the C2:C21 range.

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

After entering the formula, the system will prompt a circular reference. This is due to The formula refers to the value of the cell where the formula is located, but don't worry about it, no one cares about her.

Click the "File" → "Options" command in the upper left corner of Excel to open the File Options dialog box, switch to the "Formulas" tab, select the "Start iterative calculation" checkbox, and set the "Maximum number of iterations" ” is set to 30000. Close the dialog box with "OK".

How to find combinations whose sum is a certain value in Excel

#At this time, the formula in column C will be automatically recalculated, and the item with a non-0 recalculation result is the invoice combination. You can enter a SUM function formula in cell F2 for verification.

How to find combinations whose sum is a certain value in Excel

Let me explain to you the meaning of the formula.

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

The formula first determines C2:C21 Whether the sum of the area is equal to the target value specified in cell F1, if equal, return the value of C2 itself, otherwise, return the invoice amount in cell B2 multiplied by 0 or 1. When multiplied by 0, the result returns 0, indicating that the invoice amount is not selected. When multiplied by 1, the result returns the invoice amount itself, indicating that it is selected.

Because the formula refers to the value of the cell where the formula is located, such as the formula SUM(C$2:C$21) in cell C2, a circular reference will be triggered. At this point we enable iterative calculation, and the system will repeatedly calculate the formula until the condition for stopping iteration is established (the sum of C2:C21 is equal to the target value), or the number of iterations is exhausted.

That’s it.

Leave an exercise question at the end.

How to find combinations whose sum is a certain value in Excel

As shown in the picture above, the known sum 25 consists of 10 values. Each value is greater than or equal to 1 and less than or equal to 5. Please list these 10 values. any combination of.

Reference answer:

A3:A12 input formula

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

Related learning recommendations: excel tutorial

The above is the detailed content of How to find combinations whose sum is a certain value in Excel. 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

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools