Use calculated row number in a sumproduct reference

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
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.
Rob4077Author Commented:
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.
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Wayne Taylor (webtubbs)Commented:
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.
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.
Rob4077Author Commented:
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.
is it possible to upload a dummy file, instead of screenshot?
KoenChange and Transition ManagerCommented:
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.
Rob4077Author Commented:
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.
Ejgil HedegaardCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob4077Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.