Ask LibreOffice - RSS feedhttps://ask.libreoffice.org/en/questions/Questions and answers for LibreOfficeenSat, 01 Sep 2018 14:37:55 +0200How to find the closest value to 50?https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/Hi,
I've got a spreadsheet with a player number and points. I'd like to return the player number which is closest to 50. If there is more than one value, I'd like it to display both (or if not possible pick randomly)!
Thanks,
Naomi
![image description](/upfiles/15357852679483912.png)Sat, 01 Sep 2018 09:03:04 +0200https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/Answer by JBF for <p>Hi,</p>
<p>I've got a spreadsheet with a player number and points. I'd like to return the player number which is closest to 50. If there is more than one value, I'd like it to display both (or if not possible pick randomly)! </p>
<p>Thanks,
Naomi </p>
<p><img alt="image description" src="/upfiles/15357852679483912.png"></p>
https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/?answer=164439#post-id-164439Idea: subtract 50 from the points of each player and find the minimum of the absolute value.
Add a column C to compute abs(points-50) : C4= ABS(B4-50)
in D1 (for example) compute the min of column C : D1 = min(C4:)
You get the player number with the formula : = LOOKUP(D1;C4:C8;A4:A8) which search for the value in D1 in the array C4:C8 and return the corresponding value in array A4:A8
and the corresponding points number with the formula : = LOOKUP(D1;C4:C8;B4:B8)
Read the help of the LOOKUP function.Sat, 01 Sep 2018 14:07:34 +0200https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/?answer=164439#post-id-164439Answer by Lupp for <p>Hi,</p>
<p>I've got a spreadsheet with a player number and points. I'd like to return the player number which is closest to 50. If there is more than one value, I'd like it to display both (or if not possible pick randomly)! </p>
<p>Thanks,
Naomi </p>
<p><img alt="image description" src="/upfiles/15357852679483912.png"></p>
https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/?answer=164442#post-id-164442(What a strange idea to attach an image in such a case instead of the spreadsheet file. It's hard to make use of and it's also the greater file size. Your image was 121 KB, my file is 15KB.)
Helper columns are a good idea generally. In this case also a solution without a helper column might be advisable if no additional access to the differebces is needed elsewhere. See **[this attached example](/upfiles/15358054064355021.ods)** for a demonstration. (An image wouldn't be of any use.)
A hint in addition: You need to decide how to handle cases where more than one entry would be equally good matches, but only the first one is found. You also need to decide if the first match concerning the absolute difference shall be accepted or if you prefer another match with the opposite difference (+1 e.g. instead of -1).Sat, 01 Sep 2018 14:37:55 +0200https://ask.libreoffice.org/en/question/164426/how-to-find-the-closest-value-to-50/?answer=164442#post-id-164442