I'm attempting to use pivot tables to interpolate a value from a large, multi variable table in excel. Is there any way to interpolate on a range within a Calculated Field? (Or any other good way to accieve this).
What I'm trying to do -
I have the following table, and I'm trying to interpolate the Delta for each combination of Alpha and Beta at a Gamma of 5. With this simplified data, the answer would 15 for each set Alpha/Beta. In my real data, the Gammas and Deltas are not always nice even arrays, though they are sorted properly.
Alpha Beta Gamma Delta
A X 0 10
A X 10 20
A Y 0 10
A Y 10 20
B X 0 10
B X 10 20
B Y 0 10
B Y 10 20
What I've tried
Formula -> Calculated Field -> Formula: = INTERP(5,Gamma,Delta)
*Note that INTERP is a custom linear interpolater. yv = INTERP(xv,x,y).
Excel won't let me do that, so I was wondering if there is a better way? I could obviously just manualy pull the interpolation arrays, but my data has ~50 Alphas and ~50 Betas, so that would take a very long time. I've tried automatically pulling the arrays with a combination of INDEX and MATCH (using array formulas), and it works. The only problem is that it becomes so slow that every time the cells recalculate, it ties up the program for ~30 seconds or so.
Any ideas would be appreciated. I'm thinking of using pivot tables, but a regular formula solution or VBA solution would work too. Thanks!
Related
I've tried a few things on this and settled on a 'cheap' solution. Wanted to know if this can be done directly and more elegantly.
Problem Statement and Sample Data
Assume we have a table in excel with ~200 columns and a large number of rows (~10k).
Sample Data:
identifier
val1
val2
val3
...
val200
ID_1
100
102
34
...
89
We want to add a column at the end that shows us how many "moving average" outliers exist. A moving average outlier is defined as a point that is outside the range (mean - 2 * std deviations, mean + 2 * std deviations), where the mean and std dev is calculated using the previous 10 values (therefore its a moving average outlier).
We will not test the first 10 values. But from val11, the previous 10 values will be used to form the window and we want to test if the value is an outlier.
My Solution so far
I created another table of same dimensions as the original. In cells from val11 (to val200, for all columns), I put in the formula below in the new table. And then, I can simply sum the columns in each row in the new table.
Assume val11 is on X2 in the "shocks" worksheet (for first row):
=IF(OR(shocks!X2<AVERAGEA(shocks!D2:W2)-2STDEVA(shocks!D2:W2),shocks!X2>AVERAGEA(shocks!D2:W2)+2STDEVA(shocks!D2:W2)),1,"")
But if possible, I want to avoid having a second table since it bloats and slows down the file. Any help would be greaty appreciated
I need to create a table (either pivot or normal) that combines data laid out in this grid:
The grid shows the count of items by their size, broken down by width on one axis and height on the other. I can't figure out a way to correlate the sizes with the data. The only way I have gotten it to work so far is by manually creating table rows one by one using formulas that reference each cell.
For example, the table should read like this:
Size
Count
3 X 3
0
3 X 4
0
3 X 6
20
I'm eventually going to use this table to create a Pareto chart, but if I can create the chart from this grid that would work too.
If you can get columns K and L below to show your distinct combinations, which shouldn't take more than several minutes, then the rest is pretty easy.
Column M is simply concatenating your results to show your data how you desire.
M2 formula: =CONCAT(K2, " x ", L2)
Then column N is using a formula against your data, referencing your values in columns K and L.
N2 formula: =INDEX($A$1:$H$8,MATCH(K2,$A$1:$H$1,0),MATCH(L2,$A$1:$A$8,0))
Drag 'em down and that's it.
I'm tracking something extremely simple; a week number, and body weight.
I can't get Excel or Google Sheets to use either of those functions to predict what the weight will be for the next 4 weeks.
I have a chart like this
1 185
2 184.3
3 186
4 189
5 183
6 186
7 188
etc
I need a prediction of 8, 9, 10, 11.
I've tried =FORECAST(X57,Y53:Y56,X53:X56) where the x57 is the next week number, but what happens is Excel/sheets starts counting at a lower number than the last weight. I got a weird negative number with TREND. I know I'm not doing something right. I tried switching the ranges too.
I've inserted a screenshot from Sheets.
I feel really stupid because I should be able to figure this out but it's been over an hour of scratching my head and getting frustrated. I don't have Excel 2016 with the Forecast graph function.
Am I doing this right, but because the numbers go up and down this is Excel/Sheet's best guess?
I placed your data in G1 through H7:
2nd Order Polynomial Trendline
Equation: y = (A * x2) + (B * x ) + C
A =INDEX(LINEST(y,x^{1,2}),1)
B =INDEX(LINEST(y,x^{1,2}),1,2)
C =INDEX(LINEST(y,x^{1,2}),1,3)
So in I1 through I3, enter these equations for the coefficients A, B and C:
=INDEX(LINEST(H1:H7,G1:G7^{1,2}),1)
=INDEX(LINEST(H1:H7,G1:G7^{1,2}),1,2)
=INDEX(LINEST(H1:H7,G1:G7^{1,2}),1,3)
Then enter 8 through 11 in column G. Then H8 enter:
=$I$1*G8^2+$I$2*G8+$I$3
and copy down:
With the data in A1:B7 you could either chart that, set a trendline (linear seems reasonable) and pick up the formula from the chart:
=0.3357*(A1)+184.56
(in C1 and copied down for comparison) or apply this in B8 and copy down:
=FORECAST(A8,B$1:B$7,A$1:A$7)
The known points are used for the chart on the left and the known points plus FORECAST ones for the chart on the right:
I know you don't have Excel 2016, but here is how it would look if you insert a forecast from Excel's Data menu.
Select the cells and then click Data > Forecast Sheet. Change the Forecast End to 11. I left the Options at the defaults as displayed.
Next click Create and you will see the formulas for the forecast and the data in an Excel Table. You can inspect the FORECAST functions used, for example in column C:
=FORECAST.ETS(A9,$B$2:$B$8,$A$2:$A$8,1,1)
I want to multiply x*y until x>=20, then multiply z that value and have the results displayed as two values, the multiple and multiple*z
The question behind the formula is, how many boxes of x capacity do I need to have a total capacity of 20 liters and how much does that cost.
x = volume of bottle
y = number of bottles in a box
z = price per box
This could be done very easily by hand, but I've been playing (with little effect) in excel for a while and would like a solution.
I hope that makes sense
I rather think what you would like is the formula provided by #Jeeped but for:
I want to multiply x*y until x>=20, then multiply z that value and have the results displayed as two values, the multiple and multiple*z
label two arrays from 1 to 20 for columns and rows as shown, populate V1 with the price per box and in B2:
=IF(AND($A2*B$1>20,A2>=20),"",$A2*B$1)
and in X2:
=IF(B2="","",$V$1*B2)
with both formulae copied across 19 columns and those two sets of 20 formulae then copied down 19 rows. The result should be similar to:
I have the following excel setup that is extremely massive but here is a simplified setup:
Site1 X-Given Y-Given Site2 X-New-Given Y-Interpolated
A 10 400 A 25 550
A 20 500 A 25 550
A 30 600 A 26 560
A 40 700 B 27 570
A 50 800 B 30 600
B 10 400 B 15 450
B 20 500 B 25 550
B 30 600 B 30 600
What I'm trying to accomplish is to have each Y-Interpolated only interpolate based upon its specific site and not have any cross over. So site A would only interpolate with site A, and same with site B... so on and so forth.
I'm using the interpolate excel addin which has the following syntax:
=interpolate(x_array,y_array,x_given)
Thanks for the help!
You could try this worksheet function alternative... with data in A1:E9, enter this in F2 and fill down:
=FORECAST(E2,IF(MMULT(ROW(B$2:B$9)-LOOKUP(0,(B$2:B$9>=E2)/(A$2:A$9=D2),ROW(B$2:B$9))-0.5,1)^2<1,C$2:C$9),B$2:B$9)
Update: Here's a slightly shorter alternative entered with CTRL+SHIFT+ENTER
=PERCENTILE(IF(A$2:A$9=D2,C$2:C$9),PERCENTRANK(IF(A$2:A$9=D2,B$2:B$9),E2,20))
This assumes a positive relationship between variables and returns values at both boundaries.
Background
If you're going to use worksheet functions for this, the obvious approach is to find the neighboring two points to X: (X1,Y1) and (X2,Y2). Then calculate Y using:
Y = Y1 + (X - X1) * (Y2 - Y1) / (X2 - X1)
The problem is that this leads to a lengthy formula involving six INDEX/MATCH combinations and six more conditions for restricting data to the specified site. This leads one to look for other options...
1. The first formula looks complicated but all it's doing is applying a straight line fit based on the two neighboring points for the same site. Evaluating the formula for the third row above - by highlighting each part of the formula and pressing F9 - gives:
=FORECAST(26,{FALSE;500;600;FALSE;...},{10;20;30;40;...})
FORECAST ignores non-numeric data so the result is the same as just using {500,600} and {20,30} for the 2nd and 3rd arguments. You can use F9 on other parts of the formula to break it down further - I'll leave details to you. (The MMULT(...,1) part just changes the argument to an array so you can enter the formula without array-entry.)
2. The second formula is easier to follow. First note that in Excel percentiles are calculated by linear interpolation and the IF part is just restricting the numeric data to the specified site. Assuming data is increasing it follows that we can find the k-value in the PERCENTILE formula that matches the lookup value in the x-range and return the y-range value with that k-value. For the example in question:
26 =PERCENTILE({10,20,30,40,50},0.4)
560 =PERCENTILE({400,500,600,700,800},0.4)
To calculate the value of 0.4 the PERCENTRANK can be used which is inverse to PERCENTILE:
0.4 =PERCENTRANK({10,20,30,40,50},26)
0.4 =PERCENTRANK({400,500,600,700,800},560)
The formula above follows by combining these two functions, the last argument is set to 20 for full precision (Excel stores values internally to around 15-17 digits of precision).
Because the tool that you're using is based on a .xll add in for excel, you(or we) can not modify the code or create a custom version of interpolate that allows adding conditions.
Instead, you'll have to filter your data apart and then run the custom-function on the filtered datasets.