Excel: Rewriting Data into Buckets - excel

I have the following values in an excel column:
11
84
167
241
520
I want to rewrite these column values as a group such that:
if cell value < 50 then A
if 50 < cell value < 100 then B
if 100 < cell value < 150 then C
if 150 < cell value < 250 then D
if cell value > 250 then E
I tried the following logic but it shows A for cell A1 and false for other values:
=IF(A1<50,"A",IF(50<A1<100,"B",IF(100<A1<150,"C",IF(150<A1<250,"D",IF(A1>250,"E")))))

We do not need to put the less than "< " expression because if it was less than "<" an earlier if then statement would have returned true. Note that a number such as 50, 100, 150 250 will return false as we are not using an inclusive less than expression. Less than or equals to <= may be what you need, but from your example I cant tell
=IF(A1<50,"A",IF(A1<100,"B",IF(A1<150,"C",IF(A1<250,"D",IF(A1>250,"E")))))
For future reference you have to break this up into separate statements
AND(50<A1,A1<100,"B")
vs
IF(50<A1<100,"B")

Related

How to find if a number in a row matches a number in a column, and then automatically offset the number in the column to another value

How to find if a number in a row matches a number in a column, and then automatically offset the number in the column to another value. For example:
Row 0 1 2 3 4 5
Answer x x x x x x
Column
0 100
1 340
2 500
3 266
4 455
5 800
So if "0" in the Row array matches "0" in the Column array, then show 340 and so on. I can to this with nested IF statements but is there an easier way if you have 100s of columns. Thanks

Microsoft Excel Finding Position Based on two column data?

Fail Count Total Number Position
0 666 3
1 555 5
0 777 1
2 444 7
1 888 4
2 655 6
3 566 9
3 780 8
0 700 2
Position column is result that I need automatically by function (any combination of builtin function or custom function). Logic here is the minimum value of column (Fail count) and maximum value of column (Total Number) will first position. And minimum value of column (Fail count) and second maximum value of column (Total Number) will second position. It will continue till end data of column A and B.
How about simply sorting you data: Order by Fail Count ascending and, if equal Fail Count, by Total Number descending?
With a formula this becomes an array formula with very bad performance.
Formula in D2downwards:
{=MATCH(B2*10^(MAX($A$2:$A$1000)-A2),LARGE($B$2:$B$1000*10^(MAX($A$2:$A$1000)-$A$2:$A$1000),ROW($A$2:$A$1000)-ROW($A$1)),0)}
This is an array formula. Input it into the cell without the curly brackets and press [Ctrl]+[Shift]+[Enter] to finish.

IF statement for binning data

I have a list of numbers in the 1st column. Based on the number in the 1st column I want to give each line another number i.e. if cell A2 has a value of bigger than 1300 and less than 1400, in B2 I want the cell to show 6.75.
If A1 has a value of 1350, then B1 will update with a value of "6.75".
If A1 has a value of 1450, then B1 will update with a value of "7.25", and so on.
There are 17 groupings that I need:
<1300 >1400 =6.75
<1400 >1500 =7.25
<1500 >1600 =7.75
<1600 >1700 =8.25
.
.
.
Bigger than 2900 =14.75
I could have numerous values on the spreadsheet in the 1st column so need to put them into a grouping bucket using some formula.
Any ideas?
Something like =VLOOKUP(A3,bArray,2) should suit, copied to suit, where bArray is the name for a two column list of the breakpoints and the values up to the respective breakpoint.
The break points may require slight adjustment to suit whatever is actually required.
For a simple linear relationship like that, you could use a formula along the lines of:
=if(a1<1300, 0, if(a1>=2900, 14.75, (trunc(a1 / 100, 0) - 13) * 0.5 + 6.75))
In other words, check the too-low and too-high values first to deliver fixed results, otherwise use the final formula to convert to the desired number.
This involves dividing by 100 to turn (for example) 1727 into 17, subtracting 13 to get 4, multiplying that by 0.5 and adding the 6.25 base to get 8.75.
That will give you what you've asked for:
x < 1300: 0.00
1300 <= x < 1400: 6.75
1400 <= x < 1500: 7.25
1500 <= x < 1600: 7.75
1600 <= x < 1700: 8.25
1700 <= x < 1800: 8.75
1800 <= x < 1900: 9.25
1900 <= x < 2000: 9.75
2000 <= x < 2100: 10.25
2100 <= x < 2200: 10.75
2200 <= x < 2300: 11.25
2300 <= x < 2400: 11.75
2400 <= x < 2500: 12.25
2500 <= x < 2600: 12.75
2600 <= x < 2700: 13.25
2700 <= x < 2800: 13.75
2800 <= x < 2900: 14.25
2900 <= x : 14.75
You can see it in action from the following screen shot, showing the edge cases:
Note that you have a problem with your description of numbers like 1400 since you don't specify which range they should fall in. For the formula given above, the ranges are inclusive at the low end and exclusive at the high end (such as 1300..1399.9999).
If the relationship isn't so linear (or, more accurately, formulaic), you will probably need to consider the use of lookup tables as per the excellent suggestion by pnuts.

Excel split given number into sum of other numbers

I'm trying to write formulae that will split a given number into the sum of 4 other numbers.
The other numbers are 100,150,170 and 200 so the formula would be
x = a*100+b*150+c*170+d*200 where x is the given number and a,b,c,d are integers.
My spreadsheet is set up as where col B are x values, and C,D,E,F are a,b,c,d respectively (see below).
B | C | D | E | F |
100 1 0 0 0
150 0 1 0 0
200 0 0 0 1
250 1 1 0 0
370 0 0 1 1
400 0 0 0 2
I need formulae for columns C,D,E,F (which are a,b,c,d in the formula)
Your help is greatly appreciated.
UPDATE:
Based on the research below, for input numbers greater than 730 and/or for all actually divisible input numbers use the following formulas:
100s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 20)+1;
0;1;1;0;1;1;0;1;0;0;1;0;0;1;0;0;1;0;1;1)
150s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 10)+1;
0;0;1;1;0;1;1;0;0;1)
170s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 5)+1;
0;3;1;4;2)
200s: =CEILING(([#number]-930)/200;1) +
CHOOSE(MOD(ROUNDUP([#number]/10;0); 20)+1;
4;1;2;0;2;3;1;3;1;2;4;2;3;0;2;3;0;3;0;1)
MOD(x; 20) will return numbers 0 - 19, CHOOSE(x;a;b;...) will return n-th argument based on the first argument (1=>second argument, ...)
see more info about CHOOSE
use , instead of ; based on your Windows language&region settings
let's start with the assumption that you want to preferably use 200s over 170s over 150s over 100s - i.e. 300=200+100 instead of 300=2*150 and follow the logical conclusions:
the result set can only contain at most 1 100, at most 1 150, at most 4 170s and unlimited number of 200s (i started with 9 170s because 1700=8x200+100, but in reality there were at most 4)
there are only 20 possible subsets of (100s, 150s, 170s) - 2*2*5 options
930 is the largest input number without any 200s in the result set
based on observation of the data points, the subset repeats periodically for
number = 740*k + 10*l, k>1, l>0 - i'm not an expert on reverse-guessing on periodic functions from data, but here is my work in progress (charted data points are from the table at the bottom of this answer)
the functions are probably more complicated, if i manage to get them right, i'll update the answer
anyway for numbers smaller than 740, more tweaking of the formulas or a lookup table are needed (e.g. there is no way to get 730, so the result should be the same as for 740)
Here is my solution based on lookup formulas:
Following is the python script i used to generate the data points, formulas from the picture and the 60-row table itself in csv format (sorted as needed by the match function):
headers = ("100s", "150s", "170s", "200s")
table = {}
for c200 in range(30, -1, -1):
for c170 in range(9, -1, -1):
for c150 in range(1, -1, -1):
for c100 in range(1, -1, -1):
nr = 200*c200 + 170*c170 + 150*c150 + 100*c100
if nr not in table and nr <= 6000:
table[nr] = (c100, c150, c170, c200)
print("number\t" + "\t".join(headers))
for r in sorted(table):
c100, c150, c170, c200 = table[r]
print("{:6}\t{:2}\t{:2}\t{:2}\t{:2}".format(r, c100, c150, c170, c200))
__________
=IF(E$1<740; 0; INT((E$1-740)/200))
=E$1 - E$2*200
=MATCH(E$3; table[number]; -1)
=INDEX(table[number]; E$4)
=INDEX(table[100s]; E$4)
=INDEX(table[150s]; E$4)
=INDEX(table[170s]; E$4)
=INDEX(table[200s]; E$4) + E$2
__________
number,100s,150s,170s,200s
940,0,0,2,3
930,1,1,4,0
920,0,1,1,3
910,0,0,3,2
900,1,0,0,4
890,0,1,2,2
880,0,0,4,1
870,1,0,1,3
860,0,1,3,1
850,1,1,0,3
840,1,0,2,2
830,0,1,4,0
820,1,1,1,2
810,1,0,3,1
800,0,0,0,4
790,1,1,2,1
780,1,0,4,0
770,0,0,1,3
760,1,1,3,0
750,0,1,0,3
740,0,0,2,2
720,0,1,1,2
710,0,0,3,1
700,1,0,0,3
690,0,1,2,1
680,0,0,4,0
670,1,0,1,2
660,0,1,3,0
650,1,1,0,2
640,1,0,2,1
620,1,1,1,1
610,1,0,3,0
600,0,0,0,3
590,1,1,2,0
570,0,0,1,2
550,0,1,0,2
540,0,0,2,1
520,0,1,1,1
510,0,0,3,0
500,1,0,0,2
490,0,1,2,0
470,1,0,1,1
450,1,1,0,1
440,1,0,2,0
420,1,1,1,0
400,0,0,0,2
370,0,0,1,1
350,0,1,0,1
340,0,0,2,0
320,0,1,1,0
300,1,0,0,1
270,1,0,1,0
250,1,1,0,0
200,0,0,0,1
170,0,0,1,0
150,0,1,0,0
100,1,0,0,0
0,0,0,0,0
Assuming that you want as many of the highest values as possible (so 500 would be 2*200 + 100) try this approach assuming the number to split in B2 down:
Insert a header row with the 4 numbers, e.g. 100, 150, 170 and 200 in the range C1:F1
Now in F2 use this formula:
=INT(B2/F$1)
and in C2 copied across to E2
=INT(($B2-SUMPRODUCT(D$1:$G$1,D2:$G2))/C$1)
Now you can copy the formulas in C2:F2 down all columns
That should give the results from your table

Is there any range or between kind of function in Excel?

I have a table with three columns in Excel, a,b and c.
One cell has a numeric value X [say 25], I need to get the value in the c column such that X should be in between min and max column. For X=25 the value in c is "20" since X is between the min and max values for the 5th table row.
I'm looking for a range or between kind of function, but couldn't find a function with either name.
a b c
-----------------------------
min max improvements
0 1 70
2 5 60
6 10 50
11 20 30
21 30 20
31 40 10
41 80 5
You want to look up in that table of yours which improvement value is correct if some value is "25"; in this case that would mean to match line 5 of your table and return the value 20.
You are looking for VLOOKUP, e.g.
=VLOOKUP(B12;A2:C8;2)
giving
(edit: fixed stupid typo in formula and image, now giving correct result)

Resources