Associate values in excel between different column - excel

I have two different series of data that look something like this
A B
1 0.998
2 0.9975
3 0.997
4 0.9967
5 0.9962
6 0.9960
.
.
.
and
C D
1 240.5
1.3 249.5
1.7 241.45
2 239.0
2.5 124.5
3 125.6
3.4 235.1
3.5 236.4
.
.
.
How can I merge the two in excel so that the end results will look like this?
C C E
1 240.5 0.998
1.3 249.5 0.998
1.7 241.45 0.998
2 239.0 0.9975
2.5 124.5 0.9975
3 125.6 0.997
3.4 235.1 0.997
3.5 236.4 0.997
Essentially I need to add, for each integer of the column C, its corresponding value as shown in the series A,B. the whole dataset is 3500 rows long, so I am looking for an automated solution that can help me with that before I resolve to painstakingly paste each value in its position.

In column E you can create a formula that uses your first table (A/B) as a LOOKUP table. Truncate the value in Column C as your lookup value.
So in column E, use a formula something like,
=LOOKUP(TRUNC(Cx), A1:An, B1:Bn)
where x is the row number of your C/D/E table, and n is the last row in your A/B table.

Related

perform function on criteria in SUMIF function

I am writing a SUMIF function on a range with a format such as:
A B
1 1.1 5
2 1.2 5
3 1.3 5
4 2.1 5
5 2.2 5
I want the SUMIF to group values together by their integer, i.e.:
A B
1 1 15
2 2 10
I can do this by creating a third column C and applying INT(A) so that:
A B C
1 1.1 5 1
2 1.2 5 1
3 1.3 5 1
4 2.1 5 2
5 2.2 5 2
and (for 1)
=SUMIF(C:C, 1, B:B)
Is there a way to do this in one cell? i.e.
=SUMIF(A1:A5, "int(range) = 1", B1:B5)
I have also tried:
=SUMIF(A1:A5, "1*", B1:B5)
and
=SUMIF(A1:A5, 1&"*", B1:B5)
But these also do not work
You can use SUMPRODUCT e.g.
=SUMPRODUCT(--(INT($A$1:$A$5)=C1),$B$1:$B$5)
INT($A$1:$A$5)=C1 produces an array of TRUEs and FALSEs. The -- operator converts that to an array of 0s and 1s. Then you multiply by the values in B.
Formula in cell F12 is:
=SUMIFS($B$1:$B$5;$A$1:$A$5;">="&E12;$A$1:$A$5;"<"&E12+1)
Drag down
With Excel 365 you can do it like-
=LET(x,UNIQUE(INT(A1:A5)),y,SUMIFS(B1:B5,A1:A5,">="&x,A1:A5,"<"&x+1),CHOOSE({1,2},x,y))

Excel Swap Column of number

I am creating an excel file to swap excel columns which contains the number corresponding to the ASCII character such as low letter, upper letter, number, special characters.
Here is the original table and the corresponding letter to the number
A B C D E F G H
1 2 3 4 5 6 7 8
I want to swap each of the cell to the end. Meaning I need to swap 1 to 8. 2 to 7. 3 to 6.
A B C D E F G H
8 7 6 5 4 3 2 1
I would want to use the excel function to do this. Is there a way to achieve this? I have 156 columns.
what about this method.
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
If your data is always ordered then sorting would work.
But let's assume your data is not always alphabetically or numerically sortable, you can use a formula to reverse an unsorted list:
-
A
B
C
D
E
F
G
H
1
A
B
C
D
E
F
G
H
2
1
2
3
4
5
6
7
8
3
8
7
6
5
4
3
2
1
Rows 1 and 2 are your original data. Row 3 is the reversing formula.
Add the formula below into cell A3
=INDEX($A$2:$G$2, COLUMNS(A2:$G$2))
Note (important) that the first Range of the INDEX is absolute $A$2:$G$2, but the only the last value of the columns range is absolute A2:$G$2 (no dollars)
Either drag cell A3 across to H3 or copy cell A3 and paste over B3:H3
This has an advantage over plain sorting in that it can reverse unsorted lists for you.

VLookup with Multiple Ranges

I'm trying to make a formula that would do the following: There are say 10 categories 1-10, given a number x and y, the line is in category 3 if and only if x is between 1 and 2 and y is between 5-7 for example. I don't know how to use VLookup given the multiple conditions and the two ranges that are completely different and not in a sequential order.
I tried using index match:
=INDEX(B5:B15,MATCH(1,IF(AND(K5>=C5:C15,K5<=D5:D15),1,0)*IF(AND(L5>=E5:E15,L5<=F5:F15),1,0),0))
but this returns an error where column B are the categories, K5 and L5 are x and y respectively and column C is the lower bounds for x per category with D as upper bounds and same for E and F for y.
Here's a mock representation of the data and rules:
Data
x y category
1.2 12 1
1.5 5 2
0.98 23 3
.
.
.
Rules
Category X-LB X-UB Y-LB Y-UB
1 1 2 9 15
2 1.5 1.7 1 9
3 0.8 1 20 23
.
.
.
LB is lower bound and UB is upper bound. For example given x and y above using the rules table we find the expected return column.
Thank you,
If you have only category which will fit the bill in each case, one way is to use SUMPRODUCT.
Formula in C2 and down is
=SUMPRODUCT(($B$10:$B$12<=A2)*($C$10:$C$12>=A2)*($D$10:$D$12<=B2)*($E$10:$E$12>=B2)*($A$10:$A$12))
In M5, copied down :
=INDEX($B$5:$B$15,MATCH(1,INDEX(($K5>=$C$5:$C$15)*($K5<=$D$5:$D$15)*($L5>=$E$5:$E$15)*($L5<=$F$5:$F$15),0),0))
Or,
Another shorter option.
Using SUMIFS function, formula in M5 copied down :
=SUMIFS($B:$B,$C:$C,"<="&$K5,$D:$D,">="&$K5,$E:$E,"<="&$L5,$F:$F,">="&$L5)

Find summation and count only if they are EQUAL in Excel

In EXCEL sheet I have 1728 rows and 2 columns (L and O). I am doing addition of these 2 columns in column P. Further I want to count the occurrence in this column if addition is EQUAL to 2 or 4 or 6 or 8 BUT condition here is that The COUNT should be such that BOTH the columns L and O are EQUAL and Their addition is either 2 or 4 or 6 or 8.
This means that only the columns in L and O with values "1+1" , "2+2", "3+3", "4+4" should be counted. The addition of "1+3", "4+2" should not be counted.
=COUNTIF(P:P,4)
does not work.
L O P M
===========================
1 1 2 1 (NO OF 2'S)
2 2 4 1 (NO OF 4'S)
3 3 6 1 (NO OF 6'S)
1 3 4* NO TO BE COUNTED
4 4 8 1 (NO OF 8'S)
2 4 6* NOT TO BE COUNTED
4 2 6*
AS SEEN ABOVE RESULT OF COUNTING IS STORED IN M. Let me know the formula
=IF(L29=M29,SUMPRODUCT(--($L$29:$L$35=$M$29:$M$35)*(L29=$L$29:$L$35)),"Not Counted")
My data started in row 29 so you will need to adjust the references. It counts the entire table in 1 shot. So if you added a row to the bottom that had 1 and 1 and 2, the results in column M in your first row would become 2 and the same for the row you just added.
Will this formula help...?
=IF(AND(A1=B1,OR(SUM(A1,B1)=2,SUM(A1,B1)=4,SUM(A1,B1)=6,SUM(A1,B1)=8)),SUM(A1,B1),"NOT TO BE COUNTED")
Just drag the formula till you have data. You will need to adjust the references.
Here is the reference data.

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