Excel - sum of what range is closest to 50%

I have % values in cells A1:A60 (sum = 100%). I want to find out what range (starting from A1 downwards) will get me closest to 50%.

For example if Sum(A1:A32)=0.482 and Sum(A1:A33)=0.52, I would want it to return range A1:A32 (in actual fact, I'd want it to return the value 32 that represents the bottom of this range).

This formula needs to be repeatable over many such 1-dimensional ranges, so a 'solve' method isn't really what I'm after. I'm hoping for a tidy formula in a single cell for each range.

Many thanks!

P.S. Please assume the distribution of data within each range is random

Answers


Best I can do is this array formula**:

=MATCH(TRUE,ABS(B1-SUBTOTAL(9,OFFSET(A1,,,ROW(A1:A60)-MIN(ROW(A1:A60))+1,)))=MIN(ABS(B1-SUBTOTAL(9,OFFSET(A1,,,ROW(A1:A60)-MIN(ROW(A1:A60))+1,)))),0)

where B1 contains your desired threshold, e.g. 0.5.

Regards

**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).


Need Your Help

Xpath consuming to much CPU on Postgresql

xml postgresql xpath

I have a problem with a production software eating all cpu from db server.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.