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?
=SUMPRODUCT((MasterData!\$F\$1:\$LY\$1=B\$6)*(MasterData!\$A\$6:\$A\$2000=SiteId&TEXT(\$A8,"00"))*MasterData!\$F\$6:\$LY\$2000)/SUMPRODUCT((MasterData!\$F\$1:\$LY\$1=B\$6)*(
Microsoft Excel

Last Comment
Rob4077
SOLUTION
Wayne Taylor (webtubbs)

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Rob4077

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.
Professor J

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 https://support.office.com/en-us/article/Using-structured-references-with-Excel-tables-f5ed2452-2337-4f71-bed3-c8ae6d2b276e

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
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.
Professor J

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.
Rob4077

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
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.
Untitled.jpg
Untitled2.jpg
Professor J

Koen

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.
Rob4077

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.
24HourMicroDemo.xlsx
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Rob4077

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
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY