Fun inventory problem

excelhjalp

New Member
Joined
Aug 7, 2018
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hello!

I have a problem I can't seem to solve. This is for a rental busniess that rents out products and gets them back at a certain date.
I have four tables.

Table A: A daterange based on ID, that's a key between table A and table B
Table B: A table where one or more products can be reserved as well as how many of them. Each ID can be made of multiple products here.
Table C: An Inventory based on dates. Here a formula would be needed for the third column, inventory. It should calculate how many products are available at a given date based on Table A, B and D. It should take the total count of products from table D, and subtract the total number reserved in tables A and B and give a result, for each day specified.
Table D: A simple table where the total number of products is stated.

So the problem is: What formula can I use to calculate total products of each type in stock at a given date in the third column in Table C?

Thanks for those who give this a shot! :D

masterskjal2.3.xlsb.xlsx
ABCDEFGHIJKLMNOPQR
1Table ATable BTable CTable D (Total inventory)
2IDDate fromDate toIDProductCount of productProductDateInventoryFootball3
311.1.20222.1.20221Football2Football1.1.20221Pants5
421.1.20223.1.20221Chair2Football2.1.20223Chair10
533.1.20224.1.20222Pants3Football3.1.20223
63Chair6Football4.1.20223
7Football5.1.20223
8Pants1.1.20225
9Pants2.1.20222
10Pants3.1.20222
11Pants4.1.20225
12Pants5.1.20225
13Chair1.1.20228
14Chair2.1.20228
15Chair3.1.20226
16Chair4.1.20226
17Chair5.1.202210
18
19
20
21
Sheet1
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Does ID column in Table B refer to Dates table? In other words, is it a foreign key for Table A?
 
Upvote 0
Is ID column in Table B refers to Dates table? In other words, is it a foreign key for Table A?
Yes, you're correct. It's used to see which products and how many of them where reserved in B during the dates in A
 
Upvote 0
Here is an INDEXeption formula. I am sure there is a more efficient way. M3:
Excel Formula:
=VLOOKUP(K3,$Q$2:$R$4,2,0)-IFERROR(INDEX($H$3:$H$6,MATCH(1,($G$3:$G$6=K3)*(L3>=VLOOKUP(INDEX($F$3:$F$6,MATCH(K3,$G$3:$G$6,0)),$A$3:$C$5,2,0))*(L3<VLOOKUP(INDEX($F$3:$F$6,MATCH(K3,$G$3:$G$6,0)),$A$3:$C$5,3,0)),0)),0)
This is an array formula. You must press Ctrl+Shift+Enter together after pasting if you are not using XL365.
 
Upvote 0
Here is an INDEXeption formula. I am sure there is a more efficient way. M3:
Excel Formula:
=VLOOKUP(K3,$Q$2:$R$4,2,0)-IFERROR(INDEX($H$3:$H$6,MATCH(1,($G$3:$G$6=K3)*(L3>=VLOOKUP(INDEX($F$3:$F$6,MATCH(K3,$G$3:$G$6,0)),$A$3:$C$5,2,0))*(L3<VLOOKUP(INDEX($F$3:$F$6,MATCH(K3,$G$3:$G$6,0)),$A$3:$C$5,3,0)),0)),0)
This is an array formula. You must press Ctrl+Shift+Enter together after pasting if you are not using XL365.
Thanks Flashbond! However, it looks like this formula does not account for scenarious that contain more that one instance of products in table B, if I'm not mistaken.
 
Upvote 0
How about this one? A slightly shorter version:
Excel Formula:
=VLOOKUP(K3,$Q$2:$R$4,2,0)-SUMIFS($H$3:$H$6,$G$3:$G$6,K3,$F$3:$F$6,INDEX($A$3:$A$5,MATCH(1,(L3>=$B$3:$B$5)*(L3<$C$3:$C$5),0)))
This may handle multiple instances also. The previous code was matching only the first instances where the conditions were met. SUMIFS function should include every instance which fits the condition.
 
Last edited by a moderator:
Upvote 0
How about this one? A slightly shorter version:
Excel Formula:
=VLOOKUP(K3,$Q$2:$R$4,2,0)-SUMIFS($H$3:$H$6,$G$3:$G$6,K3,$F$3:$F$6,INDEX($A$3:$A$5,MATCH(1,(L3>=$B$3:$B$5)*(L3<$C$3:$C$5),0)))
This may handle multiple instances also. The previous code was matching only the first instances where the conditions were met. SUMIFS function should include every instance which fits the condition.
Hmm, something's not right here. This is giving me incorrect results.
 
Upvote 0

Forum statistics

Threads
1,216,178
Messages
6,129,326
Members
449,501
Latest member
Amriddin

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