SUBTOTAL nested in SUMPRODUCT

hmead

New Member
Joined
Aug 29, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I cannot figure out how this formula calculates weeks of supply in a spreadsheet I'm working on. The formula below returns the weeks of supply we have on hand today. Columns FV:HN are the weekly demand forecast, with column FV being week 35 (current week). Column CN is the current inventory available.

I mainly don't understand the SUBTOTAL and OFFSET pieces. The SUMPRODUCT is just there to return a zero and avoid negative weeks of supply, I think? But if I remove that part I get the #SPILL! error


=SUMPRODUCT(--(SUBTOTAL(9,OFFSET(FV163:$HN163,,,,COLUMN(FV163:$HN163)-COLUMN(FV163)+1))<=CN163))
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the MrExcel forum!

The COLUMN(FV163:$HN163)-COLUMN(FV163)+1

part creates an array like {1,2,3,4...} for the total number of columns in FV163:HN163. This is put into OFFSET, in the "number of columns" parameter. So OFFSET converts the range to

FV163, FV163:FW163, FV163:FX163, etc. SUBTOTAL will add up the numbers in those columns. So if FV163 = 1, and FW163 = 2, and FX163 = 7, then the sums will be {1,3,10} and so on for the rest of the columns. The reason that they used SUBTOTAL instead of SUM is because SUM does not like arrays of ranges. then the formula then resolves to:

=SUMPRODUCT(--({1,3,10}<=CN163))

So if CN163 = 8 items on hand, then this turns into

=SUMPRODUCT(--{TRUE,TRUE,FALSE})

The -- converts the TRUES to 1s, and finally the SUMPRODUCT adds up the 1s to get 2. So the sum of the first 2 columns is less than the number on hand.

Excel 365 actually has newer functions that can do this formula easier, but I don't have those functions yet. Perhaps someone else will jump in.
 
Upvote 0

Forum statistics

Threads
1,215,203
Messages
6,123,627
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top