How to evaluate a sum in excel to return 0 if the sum of two values is >0 (for my data I do not care about Positive values) - excel

I am summing loads for member design and have the correct values for downforce. However, when I use my formulas for uplift (-) if there is no uplift it returns a positive value which is objectively correct however it is not needed for my purposes. I only need negative values for uplift.
I've tried
sumif(Range,SUM(Range)<0,Sum Range)
sumif(Range,"<0")... this just returns the only negative value which is not what I need
basically, i still need to sum the data but if it returns a positive it should return zero, and if it returns a negative keep the value
Ex.)
2+3 should = 0
3-9 should = -6

You can use MIN to not allow the value to become greater than 0
=MIN(SUM(A1,A2),0)
This will make any positive number 0 because 0 is lower than any positive number.

Something like this?
=IF(SUM(J87+K87)>0,0,J87+K87)

Related

nullif when zero or negative value

I frequently use the nullif when value equals to zero, and wondering if it's possible to also display null when it equals to negative number? My current formula is NULLIF({quantity}-{quantityshiprecv} ,0) but this displays negative numbers when {quantityshiprecv} is greater than {quantity}, and I'm hoping to display null.
You just need to modify the first argument to return 0 if {quantity}-{quantityshiprecv} is negative, but still give the correct answer if it's positve. Here's one way:
NULLIF(({quantity}-{quantityshiprecv} + ABS({quantity}-{quantityshiprecv}))/2,0)
This adds the absolute value of the difference to the unchanged difference. If the difference is positive, that gives you double what you want. If it's negative the absolute (ABS()) will negate that negative value leaving you with zero. You can then divide by 2; positive is now correct, negative remains zero. The rest of the NULLIF() remains the same.

Equation to find minimum difference between given date and array of dates

I am attempting to write an equation that compares a date to an array of other dates given the same ID and then returns the minimum value found between 0 and 42 or returns a zero if the criteria does not match.
My current equation can identify whether a date pair matches the above criteria and returns a 1 if there is a match and a 0 for no match.
=IF(E15<>"",IFERROR(--(AGGREGATE(15,7,(E15-$H$2:$H$8000)/(($C$1:$C$8000=C15)*(E15-$H$2:$H$8000>=0)),1)<43),0),0)
I need to modify this equation to return the actual difference between the dates rather than just a 1 or 0.
I have been playing around with an equation like this:
=IF(E3<>"", IFERROR(IF(--(AGGREGATE(15, 6, (E3-$H$2:$H$8000)/(--($C$2:$C$8000=C3)*--(E3-$H$2:$H$8000>=0)), 1)<43)=1, MIN(--($C$2:$C$8000=C3)*(E3-$H$2:$H$8000)), ""), 0), 0)
But it returns nothing but zeros.
Please find sample data and expected values below.
For what you want you only need to move the check for less than 43 into the Aggregate and return blanks instead of 0:
=IF(E15<>"",IFERROR(AGGREGATE(15,7,(E15-$H$2:$H$8000)/(($C$1:$C$8000=C15)*(E15-$H$2:$H$8000>=0)*(E15-$H$2:$H$8000<43)),1),""),"")

Excel: How to find closest number in table, many times

Excel
Need to find nearest float in a table, for each integer 0..99
https://www.excel-easy.com/examples/closest-match.html explains a great technique for finding the CLOSEST number from an array to a constant cell.
I need to perform this for many values (specifically, find nearest to a vertical list of integers 0..99 from within a list of floats).
Array formulas don't allow the compare-to value (integers) to change as we move down the list of integers, it treats it like a constant location.
I tried Tables, referring to the integers (works) but the formula from the above web site requires an Array operation (F2, control shift Enter), which are not permitted in Tables. Correction: You can enter the formula, control-enter the array function for one cell, copy the formulas, then insert table. Don't change the search cell reference!
Update:
I can still use array operations, but I manually have to copy the desired function into each 100 target cells. No biggie.
Fixed typo in formula. See end of question for details about "perfection".
Example code:
AI4=some integer
AJ4=MATCH(MIN(ABS(Table[float_column]-AI4)), ABS(Table[float_column]-AI4), 0)
repeat for subsequent integers in AI5...AI103
Example data:
0.1 <= matches 0
0.5
0.95 <= matches 1
1.51 <= matches 2
2.89
Consider the case where target=5, and 4.5, 5.5 exist in the list. One gives -0.5 and the other +0.5. Searching for ABS(-.5) will give the first one. Either one is decent, unless your data is non-monotonic.
This still needs a better solution.
Thanks in advance!
I had another problem, which pushed to a better solution.
Specifically, since the Y values for the X that I am interested in can be at varying distances in X, I will interpolate X between the X point before and after. Ie search for less than or equal, also greater than or equal, interpolate the desired X, then interpolate the Y values.
I could go a step further and interpolate N - 1 to N + 1, which will give cleaner results for noisy data.

How can you randomly return an element from a list?

in this question we are asked to randomly return an element from a list. where "rand()" is uniformly distributed from 0 to 1. "list" is a list of elements
def r(lst):
return lst[int(random.uniform(a=0,b=1)*len(lst))]
However random.choice() is easier to use
https://docs.python.org/3/library/random.html
You should mention in the question if there are multiple answers to choose from.
return list[int(len(list)*rand())]
This is the correct answer. Multiplying the number of elements len(list) with a random number between 0 and 1 gives you a random number between 0 and len(list). You use int() to convert the value to an integer, effectively rounding it down and then select the item at that position.
return list[(len(list)/rand())]
This doesn't work. len(list) will usually be an integer > 1 and dividing that by a number between 0 and 1 always gives an even bigger number, so you always try to get an item that is after the last one in the list. Also the index will be a float, but the index must be an integer
return list[int(rand()) # i assume you wanted to use a square bracket here
This will always select the first element. It's a random number between 0 and 1 rounded down => 0
return list[len(list)} # same thing here
this will always try to select the element after the last one, which results in an error. Also, this can't even be random without the rand() function ...

Round Up the value to lowest in microsoft excel

I am writing a formula in excel in which I am diving 2 numbers and I don't want value in decimal.
I tried using ROUND(5/10,0) but it round of 0.5 to 1.
But my requirement is (0-0.99) should be evaluated as 0.
Similarly (2-2.990 should be evaluated as 2.
E.g.
(5/10) - 0 (output)
(15/10) - 1 (output)
(25/10) - 2 (output)
Thanks in Advance.
You can use the function ROUNDDOWN.
Example:
ROUNDDOWN(15/10,0)
The second parameter stands for the precision. Zero means that you won't have any decimal numbers.
You can use INT to find the next lower integer.
=INT(5/10) gives 0
=INT(15/10) gives 1
=INT(25/10) gives 2
=INT(-1/10) gives -1 (because -1 is the integer which is lower than -0.1)
=INT(-15/10) gives -2 (for a similar reason)
Use INT() or FLOOR() function to do that...
=INT(A1)
or
=FLOOR(A1,1)
If you want to use directly, then use as =INT(5/10) or =INT(15/10) ...etc.
In case of =Floor() function use as =FLOOR(5/10,1) or =FLOOR(15/10,1) ... etc

Resources