OpenOffice-Calc How to set a maximum value for a column - openoffice-calc

I'm trying to set the maximum number of a column to 50, so any number greater than 50 should show up as 50 in the spreadsheet. I'm not sure if using find and replace is the way to go. I can't seem to find a way to make find and replace look for numbers greater than 50.
Thanks

Never mind found an easy way to do it with an if statement. Ended up using
=IF(B1>50;50;B1)

Related

In google sheets how do I sum the positive difference to 10 in a range of numbers?

I have an array of numbers and for every number I want to check if it's greater than a value in another cell and if it is greater I want to add the difference to the total sum.
I have succeeded to do this "manually" for an amount of cells but there must be a better way.
For simplicity I just compared the value to 10 but it will be another cell.
=sum(if(A1>=10,A1-10,0),if(A2>=10,A2-10,0),if(A3>=10,A3-10,0))
The formula abohe yields the expected result for A1:A3.
What unfortunately doesn't work is:
=SUM(if(A1:A3>=10,A1:A3-10,0))
At the end I changed my approach to arrive at the solution:
=SUMIF(A1:A3,">10") - COUNTIF(A1:A3,">10") * 10
So instead of summing the differences directly, we sum the appropriate values and then subtract the reference as often as we summed up.
Try with this:
=SUM(ARRAYFORMULA(IF(A:A="","",IF(A:A<=10,10-A:A,0))))
try:
=BYROW(A1:A20, LAMBDA(a, IF(a>=10, a-10, 0)))
or:
=SUMPRODUCT(BYROW(A1:A20, LAMBDA(a, IF(a>=10, a-10, 0))))

Arrayformula to check if column contains text and pull the number next to it. Google Sheets

In desperate need of some assistance with this!
Wasn't sure how to title this question...
SAMPLE SHEET - CLICK ME! :)
In SupportingSheet!H1 I have the following formula:
=ArrayFormula(if(G1:G<>"", IF(DASHBOARD!N2<>"", G1:G/DASHBOARD!$P$2-filter(DASHBOARD!O1:O100,REGEXMATCH(DASHBOARD!N1:N100,E1:E100)),G1:G/(DASHBOARD!$M$3)),))
The part I struggle with is:
G1:G/DASHBOARD!$P$2-filter(DASHBOARD!O1:O100,REGEXMATCH(DASHBOARD!N1:N100,E1:E100))
It needs to divide two numbers and then subtract another number. I can't seem to get this formula to pull the correct number.
It needs to check if the text in E1:E100 exist in DASHBOARD!N1:N100, if yes, pull the number from DASHBOARD!O1:O100.
For example, text in SupportingSheet!E1 can be found in DASHBOARD!N2, hence it needs to pull the number from DASHBOARD!O2.
Column SupportingSheet!J has the actual end result that a formula needs to produce.
It doesn't look like Regexmatch works as an Arrayformula and I am not sure how to go about it.
Please note, that text in SupportingSheet!E1:E is not always identical. Often it will have a random number of "space" at the end (long story...). That is why Regexmatch was a perfect option until I realised it didn't work.
Please let me know if further clarification is needed.
Below is an image of the random spaces (non-printable characters) at the end.
use:
=ARRAYFORMULA(IF(G1:G="",,IF(DASHBOARD!N2<>"",
IFNA(G1:G/DASHBOARD!$P$2-VLOOKUP(E1:E1000, DASHBOARD!N1:O100, 2, 0),
G1:G/DASHBOARD!$M$3))))

regex for number between numbers

I'm in need of a regex, which takes a minimum and a maximum number to determine valid input, And I want the maximum and minimum to be dynamic.
I have been trying to get this done using this link
https://stackoverflow.com/a/13473595/1866676
But couldn't get it to work. Can someone please let me know how to do this.
Let's say I want to make a html5 input box, and I Want it to only receive numbers from 100 to 1999
What would a regex for this like this look like?
First off, while it is possible to do this, I think if there is a simpler way to choose a number range such as <input type="number" min="1" max="100">, that way would be preferred.
Having said that, here's how the kind of regex you requested works:
ones: ^[0-9]$ // just set the numbers -- matches 0 to 9
tens: ^[1-3]?[0-9]$ //set max tens and max ones -- matches 0 to 39
tens where max does not end in 9 ^[1-2]?[0-9]$|^[3][0-4]$ // 0 to 34
only tens: ^[1][5-9]$|^[2-3][0-9]$|^[4][0-5]$ // 15 to 45
Here, lets pick an arbitrary number 1234 to 2345
^[1][2][3][4-9]$|
^[1][2][4-9][0-9]$|
^[1][3-9][0-9][0-9]$|
^[2][0-2][0-9][0-9]$|
^[2][3][0-3][0-9]$|
^[2][3][4][0-5]$
https://regex101.com/r/pP8rQ7/4
Basically the ending of the middle series always needs to be a straight range that can reach 9 unless we are dealing with the ones place, and if it cant, you have to build it upwards toward the middle each time we have a value that can't start in 0 and then once we reach a value that cant end in 9 break early and set it in the next condition.
Notice the pattern, as each place solidifies. Also keep in mind that when dealing with going from lower to higher places, optional operators ? should be used.
Its a bit complex, but its nowhere near impossible to design a custom range with a bit of thought.
If you are more specific, we can craft an exact example, but this is generally how it is done:beginning-range|middle-range|end-range
You should only need beginning or end-ranges in certain cases like if the min or max does not end in 9. the ? means that the range that comes after it is optional. (so for example in the first case it lets us have both single and double numbers.
so for 100 - 1999 it's quite simple actually because you have lots of 9's and 0's
/^[1-9][0-9][0-9]$|^[1][0-9][0-9][0-9]$/
https://regex101.com/r/pP8rQ7/1
Note: Single values don't need ranges [n] I just added them for readability.
Edit: There used to be a regex range generator at: http://gamon.webfactional.com/regexnumericrangegenerator/. It appears to be offline now.
Essentially, you can't.
For every numeric range, there exists a regex that will match numbers in that range, therefore it is possible to write code that can generate a such regex. But such a regex is not a simple reformatting of the range ends.
However, such code would require colossal effort and complexity to write compared to code that simply checked the number using numeric methods.
With HTML 5 simply put a range input...
<form>
Quantity (between 100 and 1999):
<input type="number" name="quantity" min="100" max="1999">
</form>
with regex:
^([12345679])(\d)(\d)|^(1)(\d)(\d)(\d)
So if you need to create the regex dinamically it's possible but a bit tricky and complex

Perl: Looping Through an Array to Increment the Values of a Hash

I am new to perl and I have a problem that I'm trying to solve. At this stage in my program, I have placed a file into an array and created a hash where all the keys are numbers, that increase by a user specified bin size, within a range The values of all keys are set to 0. My goal is to loop through the array and find numbers that match the keys of my hash, and increment the corresponding value by 1 in the event of a match. To make finding the specific value within the array a bit easier, each line of the array will only contain one number of interest, and this number will ALWAYS be a decimal, so maybe I can use the regex:
=~ m{(\d+\.\d+)}
to pick out the numbers of interest. After finding the number of interest, I need to round down the number (at the minute I an using "Math::Round 'nlowmult';") so that it can drop into the appropriate bin (if it exists), and if the bin does not exist, the loop needs to continue until all lines of the array have been scanned.
So the overall aim is to have a hash which has a record of the number of times that values in this array appear, within a user specified range and increment (bin size).
At the minute my code attempting this is (MathRound has been called earlier in the program):
my $msline;
foreach $msline (#msfile) {
chomp $msline;
my ($name, $pnum, $m2c, $charge, $missed, $sequence) = split (" ", $msline);
if ($m2c =~ /[$lowerbound,$upperbound]/) {
nlowmult ($binsize, $m2c);
$hash{$m2c}++;
}
}
NOTE: each line of the array contains 6 fields, with the number of interest always appearing in the third field "m2c".
The program isn't rounding the values down, neither is it adding values to the keys, it is making new keys and incrementing these. I also don't think using split is a good idea, since a real array will contain around 40,000 lines. This may make the hash population process really slow.
Where am I going wrong? Can anybody give me any tips as to how I can go about solving this problem? If any aspects of the problem needs explaining further, let me know!
Thank you in advance!
Change:
if ($m2c =~ /[$lowerbound,$upperbound]/) {
nlowmult ($binsize, $m2c);
$hash{$m2c}++;
}
to:
if ($m2c >= $lowerbound && $m2c <= $upperbound) {
$m2c = nlowmult ($binsize, $m2c);
$hash{$m2c}++;
}
You can't use a regular expression like that to test numeric ranges. And you're using the original value of $m2c as the hash key, not the rounded value.
I think the main problem is your line:
nlowmult ($binsize, $m2c);
Changing this line to:
$m2c = nlowmult ($binsize, $m2c);
would solve at least that problem, because nlowmult() doesn't actually modify $m2c. It just returns the rounded result. You need to tell perl to store that result back into $m2c.
You could combine that line and the one below it if you don't want to actually modify the contents of $m2c:
$hash{nlowmult ($binsize, $m2c)}++;
Probably not a compete answer, but I hope that helps.

Update vlookup table array

Suppose I have the following vlookup command:
=VLOOKUP('Sheet1'!S2,'Sheet2'!$B$138:$C$145,2,FALSE)
When I drag the vlookup to the right I want it to update to
=VLOOKUP('Sheet1'!S2,'Sheet2'!$B$146:$C$153,2,FALSE)
In other words, I want the letters B and C fixed but the numbers to increment by 8. How would I do this?
It looks like your answer is always in column C and your lookup value in column A. If this is the case use INDEX MATCH
=INDEX ( C:C , MATCH ( 'Sheet1'!S2 , 'Sheet2'!$B:$C , 0 ))
I've made a few assumptions. Drop a pic of your tables and I can amend it if you can't work out which bits to change
That may be possible using some long if-then-else logic or macro but it seems an odd thing to do. The numbers represent rows so if you are incrementing them across columns I wonder whether you need to transpose your data and/or use HLOOKUP instead. There is probably a better way to achieve what you want but it is difficult to answer from the question as provided.