IF formula to calculate smallest difference between given number and multiple possibilities

dancer5

New Member
Joined
Jan 6, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I've gotten a bit stuck trying to figure out how to calculate the smallest difference between a given value and multiple others.

I have a dataset with rates and need to find out what the smallest difference is between that rate and previously known rates for that event.
The number of previously known rates will vary, so I tried using filter to get the array of all previously known rates for a specific event, but I don't know how to combine that with an IF to get the smallest difference. Since I'm not looking for MIN or MAX values, but the closest larger value to my rate to then use to get a difference.


Capture.JPG


Right now I have this formula in G2:
=IF(C2<>1, MIN(IF(E2:F7>D2, E2:F7))-D2, "")
But this doesn't dynamically change the E:F array to only look up those with the corresponding site in column A. I need a way that will find the correct values in E:F when A:A=A2 for G2, A:A=A8 for G8 etc.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
First you said
the smallest difference between a given value and multiple others.
But then
the closest larger value to my rate
Let's be really precise here--are you looking for the lowest previous rate that is higher than your rate (that is, closest rate without going under your rate), then return the difference?

Please put actual data in a post so I don't have to type all that in for testing. Thanks.
 
Upvote 0
Sorry, I'm actually looking for both. I've added a gen diff column for the smallest difference regardless if greater or less than. Here is the sample data.

siteeventavailrateprev known ratefirst known ratedifferencegen diff
111508296320
121195296
130195522
140517496
1508
1545
210458366366
220405351
231397370
241366351
250382370
2441
2
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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