how to count instances between a range in libre office calc 4 - statistics

I have a range of numbers in a1:80. I want to count the total number of values in a1:a80 that fall between X and Y e.g.
Value X = 30000
value Y = 35000
cell a1 = 34000
cell a42 = 33000
Goal: The formula will tell me that there are 2(two) instances in a1:a80 that have a value between X and Y.
I've tried a variety of combos as below:
=COUNTIF(OR($A1:$A80,"<="&V4)$a1$a80,">="&V3)
and
=IF(OR(">="&V3,"<="&W3),"there are COUNT(1)","there are COUNT(0)")
Here's the video:
http://www.youtube.com/watch?v=SKKmlSENNLM
and here's the spreadsheet:
https://plus.google.com/116948076340592829238/posts/6dDtKuEebNm
Thank you for considering this problem worthy of your time.

You may use COUNTIFS, the multi-range, multi-criterion alternative to COUNTIF:
=COUNTIFS(A1:A80;">="&$V$3;A1:A80;"<="&$V$4)

I just solved the same problem in a very simple way, although it took me some time to think of it. Just count all cells that have a value below (either including or excluding) the upper border of the range and subtract the number of cells that have a value below (incl. or excl.) the lower border of the range. For example, if you want to count the cells that contain a value that would be rounded to 9.5.
=COUNTIF(F2:F82,"<9.75")-COUNTIF(F2:F82,"<9.25")

I got an answer from a friend
=SUMPRODUCT($A$1:$A$80>=12000,$A$1:$A$80<15199)
I modified is to use a value in the spreadsheet:
=SUMPRODUCT($A$1:$A$80>=U4,$A$1:$A$80<V4)

Related

Excel - Return values between conditions of another column

I have a sheet that have Measure in meters, Value, and Distance columns (see attached screenshot). The Distance simply returns the difference between each row of the Measure column.
What I want to do is every time the Distance is greater than 10m (which I've used conditional formatting to highlight green), return in column E the measure values from the previous row up to the previous green cell, kind of like grouping them and displaying as a range. Then also return the min and max Value within that range of rows (probably in column F & G).
Ex. E6 would return something like "148000-148040" in text format, E16 would be "148090-148180", E17 would just be "148200". Then F6 = -91.09, G6 = -43.91, F16 = 15.49, G16 = 138.06 and so on.
Not sure if this would require VBA, but if it can be done with formulas that'd be great.
Sorry if this is confusing or if a similar question has been asked before.
Thank you!
I think this demonstrates the power of the new (ish) Xlookup very well (in this case, using backwards search):
For the range:
=IF(D3=10,"",XLOOKUP(TRUE,D2:D$2>10,B2:B$2,B$2,0,-1)&"-"&B2)
Min:
=IF(D3=10,"",MIN(XLOOKUP(TRUE,D2:D$2>10,C2:C$2,C$2,0,-1):C2))
Max:
=IF(D3=10,"",MAX(XLOOKUP(TRUE,D2:D$2>10,C2:C$2,C$2,0,-1):C2))

SUMIF, VLOOKUP and SUMPRODUCT formula

So I have this following spreadsheet.
Shipping WS
Col B is part number, Col C Where to ship. Col J is how many full skid and Col L how many more boxes to be added to full skip. There is a second sheet with the parts details like qty/box, box/skid, skid weight, etc...
Because everyday the is different, the number of lines in the first sheet will be different.
What I would like is a single cell at the top of the sheet that will give me total boxes going to each location that we ship to. So I want the sum of boxes for every lines that have NEWB as it destination as well as SANF. So each line calculation would be Value in K (number of full skid) * VLOOKUP of the part to get the box per skid (box per skid) + Value in L (number of loose boxes not making a full skid).
Is there a function that will do all of that for NEWB in one cell and SANF on another? The user enters the line as he goes so they are not all in groups. I might get 3 line of SANF then 2 of NEWB, then a couple of SANF and so forth.
Thanks,
Denis
I figured a way to do what I needed this weekend.
=SUMPRODUCT(K7:K52,IF(D7:D52="NEWB",1,0)*VLOOKUP(B7:B52,'Parts Data'!C3:H39,4,FALSE))
Basically I do a multiplication on every row no matter what with the sumproduct command. Number of skid (Col K) times the result of the IF statement. The IF statement will return the product of 1 times the vlookup value if the right location in Col D is what my formula is calculated for (NEWB) so basically the value of the vlookup is multiplied but number of skid for the sum. If the location is "SANF" then the product of the if command will be 0 times the value of vlookup which will give me 0, then time the number of skids, which will be 0 used for the sum.
I will copy and paste the same formula into a new cell and change "NEWB" to "SANF" in the formula for the calculation for the second location.
Hope this will help someone later.
Denis

Formula for subtracting number range in one cell from a number in another cell

I have:
a column with a number range represented as a string separated by a dash: "X-Y"
a column with a single number
What I'd like is a formula to subtract each the left and right numbers (X, Y) from the solo number to produce another range.
Example:
Range cell "5-9"
Solo number cell "2000"
Result wanted "1995-1991"
How can I produce this?
I am currently using a formula that requires me to manually enter the numbers on either side of the dash. Example (notice 5 and 9 are hard-coded):
=SUM(A31,-5)&"-"&SUM(A31,-9)
Say A1=2000
And B1="5-9"
You can use a combination of FIND, LEFT/RIGHT, and INT functions:
C1 =(A1-INT(LEFT(B1,FIND("-",B1)-1))&"-"&(A1-INT(RIGHT(B1,FIND("-",B1)-1))))
This will work with any range like "100-135"
Assuming your range numbers will be 0-9, you can use this:
=SUM(A31,-LEFT(B31,1))&"-"&SUM(A31,-RIGHT(B31,1))
(assuming the range number is in column B)
edit: #ergonaut has a better solution that will use any amount of digits.
If A1 is 2000 and B1 is 5-9:
=A1-MID(B1,1,FIND("-",B1)-1)&"-"&A1-MID(B1,FIND("-",B1)+1,99)

Let Excel Solver Operate with Natural Numbers

My workbook is a bit complicated, but the basic problem can be illustrated with a short example.
Let's assume that I have 5 cells in Excel: A, B, C, D, and E.
A = 0
B = 5 * A
C = 0
D = 10 * C
E = B + D
In the Excel Solver Function I select cell E as the objective that is to be maximised, and cells A and C as the variable cells. Furthermore, I add the constraint that cell E must not exceed 10, and the second constraint that cells A and C must be integers.
The ideal solution would be that the value in cell A should be 0, and the value in cell C should be 10. In the more complicated version of this problem, however, Excel cannot find the optional solution.
The way the current formulas look like I expect that Excel could find the right solution, if excel only used natural numbers to find the optimal solution. For example, Excel currently would look at the outcome for A = 0.01 and C = 9.99. Instead, Excel should strictly compare outcomes for variable choices such as A = 1 and C = 9.
How can I make the Excel solver function operate with natural numbers only?
I suggest you keep your current cells, and create a mirror set beside them. Each mirror cell will equal the rounded version of the original cell. ie: RoundedA will have the formula:
=ROUND(A,0)
Then when you do your data analysis, solve for the rounded version of those cells, with the changing variable being one of the "original" cells.
EDIT
As discussed below, you may need to 'trick' data validation into creating the values you want.
Assume A1 is going to be your "testing" data validation cell. B1 is a permanently blank cell. Set another cell, say, C1, equal to:
=randbetween(1,10)
This will create a random integer between 1 and 10. Set your "variable" cell to be equal to C10. So, your variable cell will always be a random number between 1 & 10 (or you could set "1" equal to the smallest number of your other variables, and "10" equal to the largest number of your other variables. This will create the scope needed to answer your question).
Then when you do data validation, make it try to get A1 = TRUE. Do this by figuring out what the 'test' condition is of your cells. Something like "when X = 0, I know that all my variables are correct". ie set A1 to:
=if(X=0,1,0)
Then do data validation by changing B1 (your blank, unrefered-to cell), waiting until A1 = 1. Does that make sense? It will turn C1 into the random cycling variable between LOWVALUE and HIGHVALUE, always using integers. Data validation will stop when A1 = 1 (which happens when some value X = 0). B1 will just spin uselessly until Data validation finds something (or it will stop after a few hundred tries if it finds nothing).
To get Solver to try larger increment divide the target cells by a large number and in such a way, each increment that solver tries is larger. (for example it changes the target cells by +-0.00001 - in that case divide the target cells by 100000 or more).

Creating Excel Function: Average of Dynamic Range

I have a list of 4000 different price values in one column. I want to calculate the average of the first X values in the column and display the result in cell "B21". The value of X can be changed and is located in cell "B20". How would I use excel functions to do this? Perhaps Average and Offset?
This will do it:
=AVERAGE(A1:INDEX(A:A,B20))
Note that a 0 or blank in B20 will average the whole column. You could filter that out with an IF statement:
=IF(B20=0,"NA",AVERAGE(A1:INDEX(A:A,B20)))
As Barry mentioned in his comment, I chose INDEX because it's not as volatile as OFFSET and INDIRECT.
How about:
=AVERAGE(INDIRECT("A1:A" & B20))
I'll throw my hat in the ring as well using the functions the op suggested.
=average(offset(A1,0,0,B20))
As Doug's comment this will also give an error with blanks or 0 in B20.
Gordon

Resources