Expanding a condensed list to find the median - excel
Column A has a x number of units and column b has an xx amount set for those number of units (a1 = 3, b1 = 100, a2 = 2, b2 = 150, etc). Is there a way to easily write out all items in column b the number of times specified in column a to easily use the median function? In this example: 100, 100, 100, 150, 150 = 100 median amount.
You could try this:
=MEDIAN(IF(FREQUENCY((SUM(B1:B4)+{0,1})/2,SUMIF(A1:A4,"<="&A1:A4,B1:B4)),A1:A4))
For example the following returns Median = 2.5
Num Amount
3 200
2 150
4 100
1 150
The ranges can be extended to fit the required data range. The Amount column is a positive integer and Num is any numerical value.
Related
Excel - sort 3 numbers MIN MAX and?
I have in Excel 3 columns with numbers, lets say x, y and z. In a fourt column I want to have them sorted and as text concatunated. Sample Col A, Col B, Col C, Col D 12 , 34 , 26 , 122634 < result 54 , 87 , 54 , 545487 I did try using MIN and MAX, but of course how to get the one between. Any sugestions?
Yes, you can use small (or large). The formula would be: =SMALL(A2:C2,1)&SMALL(A2:C2,2)&SMALL(A2:C2,3) where the 1st argument is the range of numbers and the 2nd argument is the "position" on the sorted range.
Distributing data with lower and upper boundaries in Excel
Here's a link to a screenshot with the formula used in Column B and some sample data I have a spreadsheet with 48 rows of data in column A The values range from 0 to 19 The average of these 48 rows = 8.71 the standard deviation of the population = 3.77 I've used the STANDARDIZE function in excel in column B to return the Z-score of each item in column A given that I know the mean (8.71), std dev (3.77), and x (whatever is in column A). For example (row 2) has: x = 2 z = -1.779 Using the z value, I want to create an lower (4) and upper (24) boundary and calculate what the value would be in this 3rd column. Essentially, if x = 0 (min value), then z = -2.3096, and columnC = 4 (lower boundary condition) Conversely, if x = 19 (max value), then z = 2.9947, and columnC = 19 (upper boundary condition) and then all other values between 0 to 19 would be calculated.... Any ideas how I can accomplish this with a formula in the column C?
So if your lowest original value is 0 and your highest is 19 and you want to re-distribute them from 4 to 24 and we assume that both are linear that means: Since both are linear we have to use these formulas: we develope the first to c so we get and replace the c in the second equation with that so we get and develope this to m as follows If we put this togeter with our third equation above we get: So we finally have equations for m = and c = and we can use the numbers from our old and new lower and upper bound to get: you can use these values with where x is are your old values in column A and y is the new distributed value in column B: Some visualization if you change the boundaries: Idea for a non-linear solution If you want 4 and 24 as boundaries and the mean should be 12 the solution cannot be linear of course. But you could use for example any other formula like So you can use this formula for column D y2 with the following values a, b, c as well as calculating the mean, min and max over column D y2. Then use the solver: Goal is: Mean $M$15 should be 12 secondary conditions: $M$16 = 4 (lower boundary) and $M$17 = 24 (upper boundary) variable cells are a, b and c: $M$11:$M$13 The solver will now adjust the values a, b and c so that you get very close to your goal and to get these results: The min is 4 the max is almost 24 and the mean is almost 12 that is probably the closest you can get with a numeric method.
How can I calculate the average of a set of numbers in excel with a given max?
Good afternoon, I have a table of trials that I am trying to average. There are three trials being conducted (trial one = column B, trial 2 = column C, and trial 3 = column D). Each of these trials displays a number, which can be below or above 180. I need to average these three trials, but if the number is greater than 180, then I need the average to be calculated using 180 rather than the original number. Example: Trial 1 = 159; Trial 2 = 189; Trial 3 = 73 What I would like to do: (159 + 180 + 73)/3= 137.33 Thank you!
Here's one option (array formula, so use Ctrl+Shift+Enter): =AVERAGE(IF(B2:B4>180,180,B2:B4))
SUMPRODUCT with a conditional with two ranges to calculate
To calculate a margin (JAN) I need to calculate: sales(loja1)*margin(loja1)+sales(loja2)*margin(loja2)+sales(loja3)*margin(loja3) / (SUM(sales(loja1);sales(loja2);sales(loja3)) but I need to make this using a SUMPRODUCT. I tried: =SUMPRODUCT((B3:B11="sales")*(C3:C11);(B3:B11="margin")*C3:C11))/SUMPRODUCT((B3:B11="sales")*(C3:C11)) but gave error!
When SUMPRODUCT is used to select cells within a range with text, the result for each evaluation will either be TRUE or FALSE. You will need to convert this to 1's or 0's by using '--' before the function so that when you multiply it by another range of cells, you will get the expected value SUMPRODUCT Example: Sum of column B where column A is equal to 'Sales" A B 1 | Sales 5 2 | Sales 6 3 | Margin 3 4 | Margin 2 Resulting Formula =SUMPRODUCT(--(A1:A4 = "Sales"),B1:B4) How SUMPRODUCT works: First, an array is returned that has True for each value in A1:A4 that equals "Sales", and False for each value that doesn't Sales TRUE Sales -> TRUE Margin FALSE Margin FALSE Then the double negative converts TRUE to 1 and False to 0 1 1 0 0 Next, the first array (now the one with 1's and 0's) is multiplied by your second array (B1:B4) to get a new array 1st 2nd New Array 1 * 5 = 5 1 * 6 = 6 0 * 3 = 0 0 * 2 = 0 Finally all the values in the new array are summed to get your result (5+6+0+0 = 11) Step 1: For your scenario, you're going to need find the sales amount for each Location and multiply it by the margin for the corresponding location location 1: sales * margin =SUMPRODUCT(--(A3:A11="loja1"),--(B3:B11="venda"),(C3:C11)) * SUMPRODUCT(--(A3:A11="loja1"),--(B3:B11="margem"),(C3:C11)) You can do a similar formula for location 2 and 3 and then sum them all together. Step: 2 To sum the sales for all locations, you can do a similar formula, again using the double negative, i.e. "--" SUMPRODUCT(--(B3:B11="sales"),(C3:C11)) The resulting formula will be a bit long, but when you divide Step 1 by Step 2, you'll get the desired result
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®ion 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