Subtract n from min value and then remainder of n from max value

MrSheen

New Member
Joined
Jun 26, 2014
Messages
11
As the title says, I want to subtract n from min value first and then the remainder of n from the max value. I thought I had it cracked until one of the values exceeds n.

My formula is =IF(C4=D4,C4-(B/2),IF(C4<D4,MIN(SUM(C4:D4)-B4,0),MAX(SUM(C4:D4)-B4,0))) for bot AA and BB.
<d4,min(sum(c4:d4)-b4,),max(sum(c4:d4)-b4,0)))

The expected result in E4 (AA) should be 100 and F4 (BB) should be 69 but as you can see it falls over. Can anyone make a suggestion?

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD](A1)[/TD]
[TD](B1) n
[/TD]
[TD](C1) a
[/TD]
[TD](D1) b
[/TD]
[TD](E1) aa
[/TD]
[TD](F1) bb
[/TD]
[/TR]
[TR]
[TD](A2)
[/TD]
[TD]30
[/TD]
[TD]20
[/TD]
[TD]25
[/TD]
[TD]0
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD](A3
[/TD]
[TD]30
[/TD]
[TD]17
[/TD]
[TD]14
[/TD]
[TD]1
[/TD]
[TD]0
[/TD]
[/TR]
[TR]
[TD](A4)
[/TD]
[TD]30
[/TD]
[TD]100
[/TD]
[TD]99
[/TD]
[TD]169 (Exp 100)
[/TD]
[TD]0 (Exp 69)
[/TD]
[/TR]
</tbody>[/TABLE]
</d4,min(sum(c4:d4)-b4,),max(sum(c4:d4)-b4,0)))
 
Hi AlanY,

Sorry, my brain is switched off, I blame the birth of my twin boys!

Solution in the end was this.

E2 =IF(IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))) < 0,0,IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))))
F2 =
IF(IF(C2=D2,C2-(B2/2),IF(D2 < C2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))) < 0,0,IF(C2=D2,C2-(B2/2),IF(D2 < C2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))))
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi AlanY,

Sorry, my brain is switched off, I blame the birth of my twin boys!

Solution in the end was this.

E2 =IF(IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))) < 0,0,IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))))
F2 =
IF(IF(C2=D2,C2-(B2/2),IF(D2 < C2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))) < 0,0,IF(C2=D2,C2-(B2/2),IF(D2 < C2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))))

your formula in E2 yielded 0, 30 take away the min of (20, 25) equal to 10, and minus by the max of (20, 25). shouldn't that equal to 15?
i'm still not sure the criteria for F2 etc


Excel 2013/2016
ABCDEF
1nabaabb
2302025015
330171410
4301009910069
Sheet1
Cell Formulas
RangeFormula
E2=IF(IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))) < 0,0,IF(C2=D2,C2-(B2/2),IF(C2 < D2,MIN(C2:D2)-B2,MAX(C2:D2)+MIN(MIN(C2:D2)-B2,0))))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,749
Messages
6,180,727
Members
452,995
Latest member
isldboy

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