Working formula:
=INDEX({249,749,1999,4999,9999,10000,19999,50000},RANDBETWEEN(1,COUNTA(249,749,1999,4999,9999,10000,19999,50000)))
Amendment needed
249,749,1999,4999,9999,10000,19999,50000 are fixed INDEX and can be easily RANDBETWEEN.
I want to add a range of 500 to 1500 in INDEX and RANDBETWEEN.
Is there any way to include the range of 500 to 1500 in this formula? If not then what is correct way to create a formula as per my needs.
Here is one way.
In an empty column, type your numbers 249,1999,4999,9999,10000,19999,50000. I have removed 749 as it falls in the range 500-1500. Next type 500, 501 and then drag it down to 1500. Let's say you have them in Col A. You can also do this in a separate worksheet.
So if you start at A1 then the values will go up to row 1008 as shown in the image below.
Now use this formula
=INDEX(A1:A1008,RANDBETWEEN(1,1008))
=IF(Randbetween(1,1009)<=1001,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))
A random integer is determined between 1 and the number of possible numbers. if it is less than or equal to the number in the sequential range 500 to 1500, which is 1001, then we tell then we use the randbetween (500,1500). If the initial number if greater than our range, then we have it pull a random number from our supplied list of numbers. 8 is the number of supplied numbers in the static array.
Now if I recall correctly, randbetween is a volatile function. As such anytime something in your work book changes, this formula will recalculate and provide a new number.
UPDATE:
Since you want to limit the 500-1500 range to 35% of the time, try using either of the formulas below:
=IF(Randbetween(1,100)<=35,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))
=IF(Rand()<=0.35,randbetween(500,1500),INDEX({249,749,1999,4999,9999,10000,19999,50000},randbetween(1,8)))
Related
I've got a massive parts spreadsheet that I'm trying to simplify. Various parts could be included in number of locations, which I would like to add up to a single list. The attached file is just an example using reindeer.
This is doable with using a bunch of SUMIF statements added together, but not practical due to the range of columns I need to include. There's gotta be a better way!?
=SUMPRODUCT(--($D$4:$J$11=$A4),$E$4:$K$11))
SUMPRODUCT can do that. Make sure the second range shifts one column, but has equal count of columns (and rows).
($D$4:$J$11=$A4) results in an array of TRUE's or FALSE's for the value in range $D$4:$J$11 being equal to the value in $A4 (no $ prior to it's row number will increase the row # referenced when dragged down).
Adding -- in front of the array converts the TRUE's and FALSE's to 1's and 0's respectively.
Multiplying that with the range to the right of it will result in 1* the value in $E$4:$K$11 for all TRUE's, which results in it's value, or 0* the value in $E$4:$K$11 for all FALSE's, which results in 0.
Summing the array of values results in the sum of all values where the condition is met in the column left from it.
SUMPRODUCT combines the multiplication of the array and summing the array results to 1 total sum.
You can use simply the SUM:
=SUM((D$4:$D$11=A4)*$E$4:$E$11,($F$4:$F$11=A4)*$G$4:$G$11, etc.)
where in etc you can put any range you want. If you don't use 2021/365 version, you must confirm the formula with CTRL+SHIFT+ENTER.
I have a horizontal matrix of values in Excel that I want to be able to show a quantity in a series up to a predetermined total value. If the last value in the series is less than the specified quantity then the value that will satisfy the cumulative sum is the value used. Empty values thereafter.
For example: Max cumulative sum of 200 in 7 units of 30: 30,30,30,30,30,30,20.
Should be straightforward but I've had some trouble doing it. Thanks.
I've tried nested if thens with conditional sums but the formulas seems more less helpful than the basic explanation of what's needed.
I can do most of the function but the nested if thens are too complex and are creating problematic edge cases. Hoping someone has a more concise idea.
You could combine some MOD and INT together, cell A1put this formula and drag it to the right:
=IF(COLUMN()<=200/30,30,IF(COLUMN()=INT(200/30)+1,MOD(200,30),""))
Obviously you can reference these 200 and 30 from an absolute cell address.
Example to add to 308 in steps of 14:
Formula in A1:
=IF(COLUMN()<=$A3/$A4,$A4,IF(COLUMN()=INT($A3/$A4)+1,MOD($A3,$A4),""))
Another example to add to 312 in steps of 14:
You can use Min to determine the value for each cell, and Index to specify the range
Like this (also handle returning blanks for columns past the last value)
=IFERROR(1/(1/MIN($A$2-SUM(INDEX(4:4,1,1):INDEX(4:4,1,COLUMN()-1)),$A$3)),"")
I am trying to get the max value of a column based on the Left function
What I am doing is the following :
These are the results I get when i write this into column C :
=MAX(LEFT(A:A, 2))
But what I truly want is to get in column C the max value of all column A not for each cell.
So the result should be in this case 90 for all rows.
What should be the formula here?
Just another option that gets entered normally:
=AGGREGATE(14,6,--LEFT($A$1:INDEX(A:A,MATCH("ZZZ",A:A)),2),1)
Array formulas will calculate the enitre referenced array. So care should be taken to limit the number of iterations to only the data set.
The $A$1:INDEX(A:A,MATCH("ZZZ",A:A)) part of the formula does that. It finds the last cell in column A with data in it and sets that as the upper bound. So in this instance the reference range is A1:A3. But, it will grow dynamically as data in Column A is added, so no need to change the formula each time data is added.
Update 2
Here is another solution which I think is better than my original (below)
=INT(SUMPRODUCT(MAX(SUBSTITUTE(A:A,"-",".")*1)))
it can be entered as normal (just Enter)
Orignal Answer
You need numbers and arrays
=MAX(IFERROR(LEFT(A:A,2)*1,0))
Let's break this down. Multiplying by turns your strings into numbers - since Left only returns a string
LEFT(A:A,2)*1
Unfortunately this method returns #Value if you multiply an empty string by 1. You will definitely have some empty strings in the range A:A so we wrap the whole thing with an IFERROR function.
IFERROR(LEFT(A:A,2)*1,0)
Now we still need excel to treat this as an array (i.e. a whole column of numbers, rather than just one number). So we put the MAX formula in and enter it with Ctrl+Shift+Enter rather than just Enter. The result is that the formula looks like this in the formula bar
{=MAX(IFERROR(LEFT(A:A,2)*1,0))}
which would return 90 in your example, as required
Update 1
If you are using Excel 2013 or later, you can also use the NUMBERVALUE function
=MAX(NUMBERVALUE(LEFT(A:A,2)))
again, enter it with Ctrl+Shift+Enter
I have been trying to learn to use excel "number filters". I generated 100 integers between 1 and 100 at random using ceiling(100*rand(), 1). I then labeled this column 'Scores' and used a number filter where 50 < Scores < 100. However, it is returning values outside this range, like 23, 9, 13, etc.. It seems to work fine when I actually type in numbers, so I'm assuming the seeding may be causing an issue (?). Is there a way to use the number filter on random number sets?
As Scott mentioned Rand function is volatile and one way to stop it from updating is to Copy> Paste Special> Values
The another way to accomplish this is by creating circular reference. I am assuming your "Scores" column is Column "A". In another cell say B2 enter "change". Now in the cell A2 enter your formula as =IF($B$2="change",CEILING(100*RAND(),1),A2).
If you do not want random numbers to change their values, just change the value in cell B2 to anything other then "change"
I have a spreadsheet with a lot of voltage numbers and I want to get the maximum and minimum deviations from a value (the value is 0.95).
The ideal formula would be:
=MAX(IF([range of many values]<0.95,[range of many values],""))
The range is a matrix of values, if that matters.
But this doesn't work since IF doesn't like ranges.
Is there a way to do this without creating another sheet just for the IF values results?
Thanks in advance
Use the formula
=MAX([range of many values]*([range of many values]<0.95))
as an array formula, i.e. hold hold ctrl-shift when pressing enter after typing the formula.
By entering this as an array formula, the intermediate computations can return arrays. So, ]*([range of many values]<0.95) will return an array that has 1 for True, and 0 for False. This is then multiplied by the original values in the array, entry by entry, and returns an array, which will feed into the MAX function.
BTW, your original formula will also work, if it is entered as an array formula.
There are also ways you could do this with non array formulas, e.g.
=SMALL(Range,COUNTIF(Range,"<0.95"))
That works because if there are 100 values in your range and 30 are < 0.95 then the value you want is the 30th smallest value in the range