Well, I would use the formula
((input - min) * 100) / (max - min)
For your example it would be
((65 - 46) * 100) / (195 - 46) = 12.75
Or a little bit longer
range = max - min
correctedStartValue = input - min
percentage = (correctedStartValue * 100) / range
If you already have the percentage and you're looking for the "input value" in a given range, then you can use the adjusted formula provided by Dustin in the comments:
value = (percentage * (max - min) / 100) + min
Answer from Tom on Stack OverflowVideos
Well, I would use the formula
((input - min) * 100) / (max - min)
For your example it would be
((65 - 46) * 100) / (195 - 46) = 12.75
Or a little bit longer
range = max - min
correctedStartValue = input - min
percentage = (correctedStartValue * 100) / range
If you already have the percentage and you're looking for the "input value" in a given range, then you can use the adjusted formula provided by Dustin in the comments:
value = (percentage * (max - min) / 100) + min
I put together this function to calculate it. It also gives the ability to set a mid way 100% point that then goes back down.
Usage
//[] = optional
rangePercentage(input, minimum_range, maximum_normal_range, [maximum_upper_range]);
rangePercentage(250, 0, 500); //returns 50 (as in 50%)
rangePercentage(100, 0, 200, 400); //returns 50
rangePercentage(200, 0, 200, 400); //returns 100
rangePercentage(300, 0, 200, 400); //returns 50
The function
function rangePercentage (input, range_min, range_max, range_2ndMax){
var percentage = ((input - range_min) * 100) / (range_max - range_min);
if (percentage > 100) {
if (typeof range_2ndMax !== 'undefined'){
percentage = ((range_2ndMax - input) * 100) / (range_2ndMax - range_max);
if (percentage < 0) {
percentage = 0;
}
} else {
percentage = 100;
}
} else if (percentage < 0){
percentage = 0;
}
return percentage;
}
In your example,
.
The full range is from to
. The distance between these is
, which is
.
The current value of the slider is .This is
, that is,
larger than the minimum possible value.
We are interested in the ratio . A calculator shows that
.
We want to express
as a percentage. To do that, we multiply
by
. The result is
. So the required percentage setting for
is
.
Since we will not always be dealing with the setting , let's generalize a little. Suppose that the slider setting is
. (In your question,
.)
Assume that
.
Then the distance from to the minimum
is
The ratio of this distance to the full distance
is
To turn this into a percentage, multiply by .
The answer is
Reality check: It is quite easy to make mistakes, I have done it hundreds of times. So let's see what answer we get from the above formula when . Substitute
for
. We get
. Good. Let's see what answer we get if we put
. Substitute. We get
. In general, spot checks of this kind do not guarantee that a formula is correct, but they are good evidence that we have not made a horrible blunder. (In linear cases, such as this one, two spot checks in fact do guarantee correctness.)
Now let us adjust the formula so that we can deal with a different situation, where the minimum setting is and the maximum setting is
. Let
. Then the percentage that corresponds to the setting
is given by
The reasoning that gives this formula is exactly the same as the one we used for the concrete numbers you supplied.
Now that we have a formula that gives the percentage when we know the setting
, we can use a little algebra to get a formula that gives the setting
if we are told the desired percentage
. If you have need of such a formula, and have difficulty deriving it, please leave a message.
Hi there
For your scenario and goals you need to use the VLOOKUP() function using the TRUE as last argument
The following videos will help you
https://youtu.be/-t2andiXVdk
https://youtu.be/CfMkoBfKOY4
I hope this helps you and gives you a solution to your problem
Regards
Jeovany
Hi Jeovany, thanks for the response.
the problem with Vlookup is it is reliant on the data in the table rather than a calculation, which would be more accurate. As I said, the percentage I am looking for any value between number 1 and15-million. That said if I use increments of 10,000 it is a manageable 1500 lines to 15 million. So I can use the true function accurately enough here. Thanks for the advice.
clive
Hello,
I want to build a workout tracker spreadsheet. I would love to have a functionality like in this clip: https://youtube.com/clip/Ugkx7YDbr2HkKXlPlfjKU7e5myfIMnSEQ1eI
To explain further: In this Clip he puts in one number for one lift. Lets say 100. In a filed below he has percentages "70-80%" which calculate a filed next to it "70-80". When he changes the number the calculated filed changes accordingly. If he puts in 120 the value for 120*70% and 120*80% are calculated and put into one single cell next to it.
It would look like this and the kilogram field would adjust its value based on whatever is pluged in in the first table as "max value" and the percentages of it.
| Bench | Squat |
|---|---|
| 120kg | 100kg |
| Lift | Kilogram | Percent |
|---|---|---|
| Squat | 70-80 | 70-80% |
| Bench | 60-72 | 50-60% |
| Squat | 10-90 | 10-90% |
How can you achieve this? How can you put multiple percenteges into on cell and calculate ranges of numbers from it.
Thanks everyone.