Use calculated row number in a sumproduct reference

Posted on 2016-09-14
Last Modified: 2016-09-19
I have a vary awkward data source from which I need to calculate 888 averages that use a sumproduct formulas making it painfully slow. I would therefore like to at least limit the size of the array but each time the data is updated the number of rows and columns change. It is easy enough to use a formula to calculate the bottom row number and right-most column number but how would I reference those in my sumproduct? E.g. say cell A1 contains the number of rows and c1 contains the number of columns. How would I modify the following formula to change row 2000 to A1 and column LY to cell C1 contents?
Question by:Rob4077
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 250 total points
ID: 41799155
Use the OFFSET function to return a resized range for use in your SUMPRODUCT formula...


Open in new window


OFFSET(MasterData!$A$6, 0, 0,  $A$1)

Open in new window



Open in new window


OFFSET(MasterData!$F$6, 0, 0,  , $C$1)

Open in new window

Note though that the OFFSET function is a volatile function and will recalculate whenever any cell in the worksheet recalculates, whether a precedent cell changes or not. This will have the effect of slowing down the calculation even further.

Author Comment

ID: 41799177
Thanks for the answer and for the warning. I guess that just means that the nature of my problem changes, but it won't be resolved so I might as well not bother. The frustration is that my 888 calculations take about 25 seconds to complete - not a very friendly solution.
LVL 26

Expert Comment

ID: 41799184
You can easily achieve what you need by using either of the following

1- concert your data set to Excel tables and then inside formulas use tables structured references , excel tables has the feature of dynamic range meaning that when you data expands or collapses it will take these expanded and collapsed data into count inside formulas . to convert range to table click anywhere in the table then press control + T , to learn how the structured reference of tables works refer to

2- is using dynamic named ranges , this one you would use if you do not want tables , while using option 1 is recommended. Creating named range using Index and match, Not offset then using the dynamic ranges inside the formula , if you want to use this option let me know, so that I give you example of formula
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 41799192
Tables are a good option, but INDEX is also a volatile function and whether it is used in the formula or named range still needs calculating.
LVL 26

Expert Comment

ID: 41799201
Index as indirect dependent will not trigger recalculation and in the example I referred using  INDEX as the second part of a range reference will only flag for calculating when the workbook is opened.

Author Comment

ID: 41799449
Thanks for your comments. If it helps I have included a print of a small sample of the data I am working with. Row1 is date
Row 2 are column headings
Column A is the state
Column B is the locationId
Column C is the hour of sale (1= midnight to 1AM, etc)
Other columns contain the data

What I need to do is allow user to select a LocationId (from a drop down in a cell
The result needs to display the data in a format similar to the second attachment.
This requires that I work out what week number (1-6) in the month the date falls into and then display the average for each hour within each day averaged by day within week number.
I can get it to work with SumProduct but I am looking for a faster solution.
LVL 26

Expert Comment

ID: 41799630
is it possible to upload a dummy file, instead of screenshot?

Expert Comment

ID: 41800471
I have never been able to use table references in sumproduct formulas, so I don't think that will help...
they do expand the range automatically and even copy the formulas down to added records.

Author Comment

ID: 41800849
Ok, I have create a dummy file with full current functionality. Data is extracted from another computer system and dumped into a spreadsheet. The users doing that are not tech savvy so I need to keep it very basic - no modifications to make it work. That spreadsheet is simply copied and pasted into the MasterData spreadsheet in the attached workbook starting at cell B2. Row 1 and Column A are left unchanged and serve as helper cells to make data lookups easier. I need to allow more rows and columns than appear in the report because the report columns grow every month and the number of rows can also change as locations are added and removed.

The main sheet used is Monthly and the user uses the yellow cells to select the desired location and period. That one works quite acceptably.

The problem worksheet is YTD. No selections are necessary here but it needs to display the YTD Averages. I have yet to double-check that the calculations are correct but I want to get the formulas working acceptably first. When loaded with the latest data this sheet takes up to 25 seconds on my i5 laptop to calculate.
LVL 22

Accepted Solution

Ejgil Hedegaard earned 250 total points
ID: 41802332
MasterData looks like a report from an ERP system, so each type of SiteID & Time, like 8456801, will only occur in one row.
If that is correct, then it is not needed to calculate for all 2000 rows, only the one that match.

Index (without column specification) can get all the values in the matched row, and only the values in that row.

The formula for B8 is

Then the calculation is fast.

Author Comment

ID: 41804428
Thanks to all of you for your posts. The real solution I needed was the one offered by Ejgil - worked perfectly - Thanks very much.
However I am going to split the points with Wayne because Wayne technically answered the question I asked - it was my fault that I asked the wrong question.
Thanks again one and all

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question