Lookup and calculate value based on status and date in a range

NikShah

New Member
Joined
Jul 11, 2011
Messages
10
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I am trying to calculate a value based on the remaining units (Col F) which is dependent on the status (Col C) that also is dependant on a date in the appropriate column (Cols G to I).

For example; if the status is MU then 100% (cell B3) of the remainder (cell F6) is calculated and the correct date - in this case - Col I is referenced and the value is placed in forecast box in the appropriate week.

It gets more complicated when the status is ER as 80% is calculated for one week and the remaining 20% in another week specified in Col G to I.

Please see screenshot below for the desired result.

Many thanks in advance!

Regards,
 

Attachments

  • Forecast model screenshot.jpg
    Forecast model screenshot.jpg
    92.1 KB · Views: 10

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I tried to use the following formulas and each of them works in isolation, but I just cannot seem to combine them!

=IF($C6="MU",IF(AND($I6>=K$5,$I6<L$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),0))
=IF($C7="ER",IF(AND($H7>=K$5,$H7<L$5),($F7*VLOOKUP($C7,$A$1:$B$3,2,0)),IF(AND($I7>=K$5,$I7<L$5),($F7*(1-VLOOKUP($C7,$A$1:$B$3,2,0))),0)))
=IF($C8="FR",IF(AND($G8>=K$5,$G8<L$5),($F8*VLOOKUP($C8,$A$1:$B$3,2,0)),0))
 
Upvote 0
A couple of suggestions that should help get you better/faster responses for any future question:
  1. Update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

  2. Investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.
See if this does what you want. It assumes column J is blank as in your image.

NikShah.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1FR100%
2ER80%
3MU100%
4
5RemainingFR dateER dateMU date22/03/202129/03/20215/04/202112/04/202119/04/202126/04/20213/05/202110/05/202117/05/202124/05/202131/05/20217/06/2021
6MU207/04/2021  20         
7ER10025/03/202120/05/202180       20   
8FR1003/05/2021      100     
Sheet1
Cell Formulas
RangeFormula
K6:V8K6=IF(LOOKUP(MIN($G6:$I6),$K$5:$V$5)=K$5,$F6*VLOOKUP($C6,$A$1:$B$3,2,0),IF(AND($C6="ER",LOOKUP(MAX($G6:$I6),$K$5:$V$5)=K$5),$F6-SUM($J6:J6),""))
 
Upvote 0
Hi Peter,

Apologies for the delay. I couldn't download the XL2BB add on as this is a company computer.

Your solution is way more elegant than mine and works!

If you delete column J then I get the following solution for cell J6:

=IF($C6="MU",IF(AND($I6>=J$5,$I6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),0),
IF($C6="ER",IF(AND($H6>=J$5,$H6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),IF(AND($I6>=J$5,$I6<K$5),($F6*(1-VLOOKUP($C6,$A$1:$B$3,2,0))),0)),
IF($C6="FR",IF(AND($G6>=J$5,$G6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),0),0)))

Thank you once again.
 
Upvote 0
If you delete column J then I get the following solution for cell J6:

=IF($C6="MU",IF(AND($I6>=J$5,$I6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),0),
IF($C6="ER",IF(AND($H6>=J$5,$H6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),IF(AND($I6>=J$5,$I6<K$5),($F6*(1-VLOOKUP($C6,$A$1:$B$3,2,0))),0)),
IF($C6="FR",IF(AND($G6>=J$5,$G6<K$5),($F6*VLOOKUP($C6,$A$1:$B$3,2,0)),0),0)))
If column J is deleted, then you could use this slightly adjusted version of my previous formula

NikShah.xlsm
ABCDEFGHIJKLMNOPQRSTU
1FR100%
2ER80%
3MU100%
4
5RemainingFR dateER dateMU date22/03/202129/03/20215/04/202112/04/202119/04/202126/04/20213/05/202110/05/202117/05/202124/05/202131/05/20217/06/2021
6MU207/04/2021  20         
7ER10025/03/202120/05/202180       20   
8FR1003/05/2021      100     
Sheet3
Cell Formulas
RangeFormula
J6:U8J6=IF(LOOKUP(MIN($G6:$I6),$J$5:$U$5)=J$5,$F6*VLOOKUP($C6,$A$1:$B$3,2,0),IF(AND($C6="ER",LOOKUP(MAX($G6:$I6),$J$5:$U$5)=J$5),$F6-SUM($I6:I6)+$I6,""))
 
Upvote 0
If you enter a date in cell H6, say, 23/3/21, then the formula doesn't work as it will enter a value in cell J6 instead of the correct cell L6. Basically what I'm trying to say that in the past we would have had an early release date, but it's the status that should be driving which date column should be picked up.
 
Upvote 0
OK, now I understand (I think! :)). From your previous example and description I thought it was only "ER" rows that would have two dates.

See if this is better.

NikShah.xlsm
ABCDEFGHIJKLMNOPQRSTU
1FR100%
2ER80%
3MU100%
4
5RemainingFR dateER dateMU date22/03/202129/03/20215/04/202112/04/202119/04/202126/04/20213/05/202110/05/202117/05/202124/05/202131/05/20217/06/2021
6MU2023/03/20217/04/2021  20         
7ER10025/03/202120/05/202180       20   
8FR1003/05/2021      100     
Sheet4
Cell Formulas
RangeFormula
J6:U8J6=IF(LOOKUP(INDEX($G6:$I6,MATCH($C6&"*",$G$5:$I$5,0)),$J$5:$U$5)=J$5,$F6*VLOOKUP($C6,$A$1:$B$3,2,0),IF(AND($C6="ER",LOOKUP(MAX($G6:$I6),$J$5:$U$5)=J$5),$F6-SUM($I6:I6)+$I6,""))
 
Upvote 0
Solution
Are you able to advise what this part of the formula is doing? At the moment it's not adding anything from the date column (Col I).
1618416075221.png
 
Last edited by a moderator:
Upvote 0
Are you able to advise what this part of the formula is doing? At the moment it's not adding anything from the date column (Col I).
We don't want it to add anything from the date column. That part of the formula is like that so that we can use the same formula in all columns. If we had a separate formula for column J then another formula for all the other columns we wouldn't need that part of the formula to be quite like that. That part of the formula is to calculate the second value in the "ER" rows like in cell R7 in my sheet above. In that cell, that part of the formula you marked is
$F7-SUM($I7:Q7)+$I7
It sums all the values from I7:Q7 and subtracts that from F7 (100). However, the sum that was subtracted includes the date from I7 which should not be subtracted so it is added back on at the end. This results in the 20 you see in R7.
 
Upvote 0
We don't want it to add anything from the date column. That part of the formula is like that so that we can use the same formula in all columns. If we had a separate formula for column J then another formula for all the other columns we wouldn't need that part of the formula to be quite like that. That part of the formula is to calculate the second value in the "ER" rows like in cell R7 in my sheet above. In that cell, that part of the formula you marked is
$F7-SUM($I7:Q7)+$I7
It sums all the values from I7:Q7 and subtracts that from F7 (100). However, the sum that was subtracted includes the date from I7 which should not be subtracted so it is added back on at the end. This results in the 20 you see in R7.
Ah ok. Understood. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,090
Members
448,944
Latest member
sharmarick

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