Question

Array formula - can you break it down and explain how it works

Asked by: bobinorlando

I understand the overall concept of an array formula. But can you break down this complex formula and explain how it works?

=IF(ROW()-6>SUMPRODUCT((Sheet1!$B$3:$B$10=Sheet2!$B$3)*1),"",INDEX(Sheet1!C$3:C$10,SMALL(IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10)),ROW()-6)-MIN(ROW(Sheet1!C$3:C$10))+1))

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-01 at 05:04:06ID24697598
Topic

Microsoft Excel Spreadsheet Software

Participating Experts
3
Points
500
Comments
5

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Help with sumproduct formula?
    =SUMPRODUCT(([Schedule.xls]AL!$B$2:$B$1499="Anaheim")*([Schedule.xls]AL!$N$2:$N$1499=7.5)*[Schedule.xls]AL!$M$2:$M$1499) Can anyone see the error? Says "A value in the formula is the wrong data type" im assuming its the "7.5" but i had tried i...
  2. Lookup value in sheet1 from value in sheet2.
    I have a name column in sheet1 & 2, however the name column in sheet1 is "lastname,firstname middle initial" and the name column in sheet2 is "lastname, firstname (notice the space after the comma) middle initial". Is there anyway to do a lookup since...
  3. Replacement of SUMPRODUCT formula
    Hi Experts I use the following formula to count how many times two values appear in the same row of data. =SUMPRODUCT((Sheet1!A1:A100="Company1")*(Sheet1!B1:B100="Site1")) This does actually work fine, but i have a worksheet that contains about 150 of t...
  4. SumProduct IF Array
    I have 2 excel sheets. Sheet 1 has my data in 2 columns. Column A are price points ranging from $0 to $30. Column B are the number of customers on the price price points in Column B. On Sheet 2, I have a summary where I would like to have a formula look for the price points ...
  5. Sumproduct in VB
    Hi... I understand the sumproduct well enough and i know how to apply it...But my problem is..if i apply the same formula in VB it gives me an error...What i want to understand how do you apply sumproduct in VB through application.worksheetfunction...here is a sample of what...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: joaoalmeidaPosted on 2009-09-01 at 05:33:02ID: 25230851


The array formula is executed for each cell in the range. For this particular formula:

=IF(ROW()-6>SUMPRODUCT((Sheet1!$B$3:$B$10=Sheet2!$B$3)*1),"",INDEX(Sheet1!C$3:C$10,SMALL(IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10)),ROW()-6)-MIN(ROW(Sheet1!C$3:C$10))+1))

If the number of the ROW minus 6 (ROW()-6) is greater than the count of values in Sheet1!$B$3:$B$10 equal to Sheet2!$B$3, then return empty string,

Else

Return the value in CELL that is column Sheet1!C and first ROW number that has one of the following conditions:

(Sheet1!$B$3:$B$10=Sheet2!$B$3) First Row that matches Sheet2!$B$3
OR
Current ROW minus 6 minus the minimum ROW number from Sheet1!C$3:C$10 plus 1



 

by: x-menPosted on 2009-09-01 at 05:56:04ID: 25231034

there are errors in the formula, could it be more like this:

=IF(ROW()-6>SUMPRODUCT((Sheet1!$B$3:$B$10,Sheet2!$B$3)*1),"", INDEX(Sheet1!C$3:C$10, SMALL(IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10),ROW()-6),MIN(ROW(Sheet1!C$3:C$10))+1)))

 

by: mvidasPosted on 2009-09-01 at 06:15:38ID: 25231204

Hi,

I'd be glad to break it down for you, so you can update it in the future (if you decide not to go the pivot table route, which is probably the better way to go).

First, the original formula:
=IF(ROW()-6>SUMPRODUCT((Sheet1!$B$3:$B$10=Sheet2!$B$3)*1),"",INDEX(Sheet1!C$3:C$10,SMALL(IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10)),ROW()-6)-MIN(ROW(Sheet1!C$3:C$10))+1))

First I'll tackle the Logical Test and True Portion of the initial IF() function IF(ROW()-6>SUMPRODUCT((Sheet1!$B$3:$B$10=Sheet2!$B$3)*1),"",. This tells excel that if we've retrieved all the matching records, then return a blank string "" instead

ROW()-6 I use to retrieve the current "record number", since you're starting at row 7 on Sheet2. Since ROW() would return 7, i subtract 6 so the first would return 1, then 2, etc. I'll substitute this part of the formula with the MatchNum for easier readability. This also appears later in the original formula as well.

SUMPRODUCT((Sheet1!$B$3:$B$10=Sheet2!$B$3)*1) I use to retrieve the number of matching records. This checks the range Sheet1!B3:B10, which has the dates, and checks how many match the date you enter at Sheet2!B3. I could have also used COUNTIF() for this; I decided to use sumproduct in case you want to use any other matching criteria from the first page. I'll substitute this with the NumOfMatchingRecords for easier readability.  


This leaves us with:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(Sheet1!C$3:C$10,SMALL(IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10)),MatchNum)-MIN(ROW(Sheet1!C$3:C$10))+1))

The other IF() function in there, IF((Sheet1!$B$3:$B$10=Sheet2!$B$3),ROW(Sheet1!C$3:C$10)), would not work by itself. However, as part of the array formula, this returns an array of each matching row number where the date field (Sheet1!B3:B10) matches the specified date (Sheet2!B3). The ROW() function, like above with MatchNum, simply returns the row number. As part of the array formula, it returns all of the matching row numbers. I use column C on Sheet1 in the initial formula, though I could have used B or any other column, as long as the rows (3:10) match the rows from the logical test. I'll substitute this with MatchingRows for easier readability.

This leaves us with:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(Sheet1!C$3:C$10,SMALL(MatchingRows,MatchNum)-MIN(ROW(Sheet1!C$3:C$10))+1))

The SMALL() function in there, SMALL(MatchingRows,MatchNum), is used to return the n-th matching row number from the list (matchingrows), based on the current record number (matchnum). I'll substitute this with MatchingRowNumber for easier readability.

This leaves us with:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(Sheet1!C$3:C$10,MatchingRowNumber-MIN(ROW(Sheet1!C$3:C$10))+1))

We're looking now at the portion MatchingRowNumber-MIN(ROW(Sheet1!C$3:C$10))+1. One problem we face is that MatchingRowNumber returns the actual row number (3 through 10, in your example). For use in the INDEX() function later, we would actually want it to return the relative row number (1 through 8, in your example) within the dataset.  To fix this, I subtract the portion MIN(ROW(Sheet1!C$3:C$10)). This returns the minimum row number of the given array. In your spreadsheet, this is 3. I then add 1, to get us the relative row number.
For example, if we wanted the 1st match with a specified date of 8/27/09, then MatchingRowNumber returns 7. However, that is the 5th row within that dataset. If we subtract 3 (MIN(ROW())) and add 1, we get the value 5 that we want. I'll substitute WhichRelativeMatchingRow for easier readability.

This leaves us with:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(Sheet1!C$3:C$10,WhichRelativeMatchingRow))

We are now looking at the INDEX() portion of this, INDEX(Sheet1!C$3:C$10,WhichRelativeMatchingRow). This simply returns the value in the specified datarange (Sheet1!C3:C10) at the relative matching row number. Using our previous example, WhichRelativeMatchingRow would be the value "5". The 5th value in our specified datarange here is "John", so that is what gets returned. I left the "$" off before the column C so that it would change to D,E,F when you copied the column to the right (for gross calls, dead air, call backs).

This should explain the array formula for you.  I'm going to make another post to explain how to do all this using named ranges, which will make the formula this readable in your spreadsheet.  I'd do it here, but this is obviously long enough as it is :)

Matt

 

by: mvidasPosted on 2009-09-01 at 06:39:27ID: 25231431

Re: Named ranges. We'll be adding a few named ranges to your workbook. I believe you have Excel 2003 or previous, so go to Insert -> Names -> Define. (If you have 2007, go to the Formulas tab and click Define Name)

First, lets get your data range, and make it bigger for when you add more data to it. Assuming you're at the Define Name window:

Type DateRange in the box at the top, and in the RefersTo box paste in =Sheet1!$B$3:$B$65536, and click Add.

Next, type in Artists at the top, and paste =Sheet1!$C$3:$C$65536 at the bottom, and click Add.

Next, put GrossCalls at the top, and =Sheet1!$D$3:$D$65536 at the bottom, and click Add.

Next, put DeadAir at the top, and =Sheet1!$E$3:$E$65536 at the bottom, and cilck Add.

Next, put CallBacks at the top, and =Sheet1!$F$3:$F$65536 at the bottom, and click Add.

Next, put DateToMatch at the top, and =Sheet2!$B$3 at the bottom, and click Add.

Next, put MatchNum at the top, and =ROW()-6 at the bottom, and click Add.

Next, put NumOfMatchingRecords at the top, and =SUMPRODUCT((DateRange=DateToMatch)*1) at the bottom, and click Add.

Next, put MatchingRows at the top, and =IF((DateRange=Sheet2!$B$3),ROW(DateRange)) at the bottom, and click Add.

Next, put MatchingRowNumber at the top, and =SMALL(MatchingRows,MatchNum) at the bottom, and click Add.

Next, put WhichRelativeMatchingRow at the top, and =MatchingRowNumber-MIN(ROW(DateRange))+1 at the bottom, and click Add.


With that all done, go to your sheet 2.
In A7, paste the formula:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(Artists,WhichRelativeMatchingRow))

In B7, paste:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(GrossCalls,WhichRelativeMatchingRow))

For C7 use:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(DeadAir,WhichRelativeMatchingRow))

For D7 use:
=IF(MatchNum>NumOfMatchingRecords,"",INDEX(CallBacks,WhichRelativeMatchingRow))

And fill those formulas down as needed.  These are much easier to read and audit, and all the array formulas are in the named ranges so you don't need to worry about the ctrl-shift-enter (should someone else need to edit the spreadsheet).

I'm attaching your spreadsheet with these changes made, should you need/want it.
Let me know if there is anything else!
Matt

 

by: bobinorlandoPosted on 2009-09-01 at 06:52:50ID: 31622955

Wow! Thank you!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...