Remove a constant from every cell of a column in an Excel equation - excel

I have a column of coefficients and values
(Column A) (column B)
0.5 17.0
0.2 15.0
1.0 21.0
0.7 30.0
And I want to sum a constant and each coefficients in the column, e.g.
(1.0-0.5)*17.0 + (1.0-0.2)*15.0 + (1.0-1.0)*21.0 + (1.0-0.7)*30.0
Here, the constant is 1.0. What is the equation that is needed to achieve that? I have tried something like
SUMPRODUCT((1-A:A),B:B)
Without success.

How about:
=COUNT(A:A)-SUM(A:A)
This for for the constant 1. If the constant was 7 then use:
=7 * COUNT(A:A)-SUM(A:A)
EDIT#1:
Based on your Edit, I tried your proposed formula and it worked just fine!:

Related

Excel interpolate with hlookup

I have a table with x,y values. I want to interpolate for a given x1 value between the y values using the hllokup function also. I have found fomrulas for vlookup and xlookup but not for hlookup. I cannot use xlookup becaus eogf the verison of excel I use.
Example:
x-values 0.2 0.5 0.8 1.0 1.25 1.5 1.75 2.0 2.5 3.0 4.0
y-values 0.1 0.11 0.12 0.15 0.18 0.2 0.23 0.24 0.28 0.31 0.32
I need the y-value for x=1.1
I appreciate any help
There are various ways to interpolate: spline, polynomial, linear and so on.
I assume that you want linear interpolation between 2 x values.
In this case first of all, you need to find closest larger and closest lower x values:
Lower x:
=MAX(IF(B1:L1<B5,B1:L1))
Larger x:
=MIN(IF(B1:L1>B5,B1:L1))
Now need to find corresponding y's with HLOOKUP.
Lower x's y:
=HLOOKUP(A9,B1:L2,2,FALSE)
Larger x's y:
=HLOOKUP(B9,B1:L2,2,FALSE)
Now that you have all needed values you can write linear interpolation formula or you can use excel formula FORECAST. With 2 x's and 2 y's it will work as linear interpolation.
=FORECAST(B5,A11:B11,A9:B9)
Formula without using helper cells:
=FORECAST(B5,CHOOSE({1,2},HLOOKUP(MAX(IF(B1:L1<B5,B1:L1)),B1:L2,2,FALSE),HLOOKUP(MIN(IF(B1:L1>B5,B1:L1)),B1:L2,2,FALSE)),CHOOSE({1,2},MAX(IF(B1:L1<B5,B1:L1)),MIN(IF(B1:L1>B5,B1:L1))))
Result:

Read_excel reads cells with formulae as NaN (instead of the actual value)

path = "C:\\Users\\Adam\\Desktop\\Stock Trackers\\New folder\\New folder\\Stock Tracker WK36 mTeam.xlsx"
df = pd.read_excel(path,usecols="A:D,R",index_col=None)
Column R (in the file path above) is a column with a simple SUM formula. When I use read_excel as above, Columns A-D (in the resulting dataframe df) are fine as these are constants but column R is displayed with all NaN. How can I use pandas to read the underlying cell value instead of displaying NaN?
If you are interested in getting the results of an excel formula computation into a data frame, Given an Excel sheet which looks like the following:
where the Total Qty column is a formula of the form sum(D:F), and the last column is a formula of the form G*C and the formula in cell h5 is sum(h2:h4).
When reading directly into a df using pandas.read_excel(fileName_) yields:
item Description Unit Cost Part A Qty Part B Qty Part C Qty Total Qty Total Cost
0 1.0 System A 25.10 1.0 2.0 1.0 4.0 100.4
1 2.0 Part B 15.25 3.0 0.0 3.0 6.0 91.5
2 3.0 Part C 6.30 6.0 5.0 1.0 12.0 75.6
3 NaN Sum NaN NaN NaN NaN NaN 267.5

How to use Index, Match and Product functions in excel for this questions?

Week # 1 2 3 4 5
Ratio 0.9 0.9 0.8 0.8 0.6
Select week from Drop Down List ____ (we have 1,2,3,4,5 inside)
So how can we use index,match,product or other excel formulas for performing the following task:
If 3 is selected from the dropdown list, then we multiply 0.90.90.8
If 2 is selected from dropdown list, then we multiply 0.9*0.9
Can you please help?
I could not find how to use index match or this
You can use PRODUCT and INDEX to achieve this. No need for MATCH here. Take a look at this example:
A
B
C
D
E
F
G (your dropdown)
H
1
week
1
2
3
4
5
3
=PRODUCT(B2:INDEX(B1:F2,2,H1))
2
ratio
0.9
0.9
0.8
0.8
0.6
In case your weeks do not start at one, you do have to use MATCH:
=PRODUCT(B2:INDEX(B2:F2,1,MATCH(H1,B1:F1)))
with Office 365 you could also do this using TAKE:
=PRODUCT(TAKE(B2:F2,,H1))
Where H1 is the dropdown selection:
Else use =PRODUCT(B2:INDEX(B2:F2,,H1))

Getting average of top 1/3, second 1/3, and last 1/3 of values in column

I have a column with numbers and a reference column. I'm trying to separate the numbers column into first third, second third, and last third and take the average of each.
Values Ref column
1.7 cow
2.3 cow
2.6 cow
1.8 sheep
1.3 sheep
2.2 sheep
1.5 sheep
1.2 sheep
2.3 sheep
1.5 goose
2.5 goose
So, for example, the average of the first two values for "sheep", second two, and last two. In other words, I want to take the average of each 1/3 of cells adjacent to "sheep".
Add a column to cumulatively count the instances of the word you're looking at, then check that row number in your AVERAGE.
C2 = =CountIf($B$2:$B2, $B2) and fill down => values should be {1,2,3,1,2,3,4,5,6,1,2}
E1 = sheep
E2 = =CountIf($B:$B, $E$1) => 6
E3 = {=Average(If(($B:$B = $E$1) * ($C:$C <= $E$2 / 3), $A:$A))} (note this is an array formula, as designated by the {} around it) => 1.55
E3 = {=Average(If(($B:$B = $E$1) * ($C:$C > $E$2 / 3) * ($C:$C <= 2 * $E$2 / 3), $A:$A))} => 1.85
E3 = {=Average(If(($B:$B = $E$1) * ($C:$C > 2 * $E$2 / 3), $A:$A))} => 1.75
Array formulas, if I remember correctly, are entered the same as normal formulas (don't include the {}, that gets entered automatically), but you press Ctrl (and possibly Shift) with Enter when you finish.
NB - these look at the entire column. You can speed them up by changing $A:$A to $A$2:$A$12 (likewise for $B:$B and $C:$C). Just bear in mind that for any data you append to this list, you'll need to update the formulas; but you can insert data into the middle of the list and it will update them automatically.
use a formula like this:
=AVERAGE(INDEX(A:A,MATCH($D$2,B:B,0)+(D3-1)*COUNTIF(B:B,$D$2)/3):INDEX(A:A,MATCH($D$2,B:B,0)+((D3)*COUNTIF(B:B,$D$2)/3)-1))
This does require that the ref column be sorted and like references grouped.
This array formula will return the averages even if not sorted:
=AVERAGE(INDEX(INDEX(A:A,N(IF({1},MODE.MULT(IF($B$1:$B$12=$D$2,ROW($A$1:$A$12)*{1,1}))))),N(IF({1},ROW(INDEX(A:A,1+(D3-1)*COUNTIF(B:B,$D$2)/3):INDEX(A:A,D3*COUNTIF(B:B,$D$2)/3))))))
array formula need to be entered with Ctrl-Shift-enter instead of Enter when exiting edit mode.
Well supposing there were 7 sheep values and you wanted to do a weighted mean (e.g. the first mean would be calculated from the first two sheep plus a third of the third one)?
I have attempted a general solution for this dividing any number of animals into any number of fractions and finding their average values. My approach is to use the elegant overlap formula from #Barry Houdini as used here and work out the overlap between the intervals (in the case of 7 animals divided into 3):
0 to 2.33
2.33 to 4.67
4.67 to 7
and the numbers of the animals
0 to 1
1 to 2
2 to 3
and so on.
In H4
=IF(ROWS($1:1)<=$H$2,ROWS($1:1)/$H$2*COUNTIF(B$2:B$16,$G$2),"")
In G4
=IF(H4="","",H4-COUNTIF(B$2:B$16,$G$2)/$H$2)
The main formula in I4 is
=IF(H4="","",SUM(TEXT(IF(C$2:C$16<H4,C$2:C$16,H4)-IF((C$2:C$16-1)>G4,C$2:C$16-1,G4),"general;\0")
*A$2:A$16*(B$2:B$16=$G$2))/(COUNTIF(B$2:B$16,$G$2)/$H$2))
entered as an array formula.
The fractions can be changed to halves, quarters etc. by changing the number in H2.

Excel replace numbers with custom unequal ranges

Suppose I have the following data
Name Output
A 0.1
B 7
C 0.4
D 0.9
E 1.1
F 12
G 22
I would like replace the output variable by custom ranges:
Name Output Output_2
A 0.1 0m-0.3m
B 7 6y-10y
C 0.4 0.4m-0.6m
D 0.9 0.7m-1y
E 1.1 1y-5y
F 12 11y-20y
G 22 21y-40y
Right now, I am doing this (a long list of nested IFs)
=IF([#Tenor]<= 0.25, "0m-3m", IF([#Tenor]<=0.5, "4m-6m", IF([#Tenor] <= 1, "7m-1y",IF([#Tenor]<=5,"2y-5y",IF([#Tenor]<=10,"6y-10y",IF([#Tenor]<20,"11y-20y",IF([#Tenor]<40,"20y-40y")))))))
and it works but I am concerned that as the number of ranges increases, this will be painful to write. I was hoping I could write down a range somewhere and ask excel to look it up and do some case type thing.
Let's assume your first three columns are A, B and C (like in the second code block you posted). Add the following data into columns E and F (this will be your mapping data):
Output Output2
0 0m-3m
0.25 4m-6m
0.5 7m-1Y
1 2y-5y
5 6y-10y
10 11y-20y
20 20y-40y
40 20y-40y
Then write the following formula into C2 cell and drag it down:
=INDEX($F:$F,MATCH(B2,$E:$E,1))
UPDATE: you can do this even simpler with approximate VLOOKUP:
=VLOOKUP(B2,$E:$F,2,1)

Resources