Selecting a row in excel based on specific values in 2 columns, - excel

Data roughly in the format
A B C
ID1 ID2 0.5
ID1 ID3 0.7
ID2 ID3 0.9
I want to create a correlation matrix (column C being the correlation between the IDs in A and B). It can definitely be done with a pivot table, though I have to use sum which could be risky if a duplicate existed since an error might not be apparent. Output format would be:
ID1 ID2 ID3
ID1 1 .5 .7
ID2 .5 1 .9
ID3 .7 .9 1
(the '1' is easily done with an =IF(B$2=$A3,1,0) and replacing 0 with the formula to find the correlation)
I basically want a match (col a= ID1 && col b = ID2). I suspect it could be done by concatenation, but I am not sure that is a great solution? Match/Vlookup etc only return the first match [in that column], which is no good to me. Ode to a 'where' clause I guess?
My searches did not reveal any usuable help, I have already calculated the correlation and am putting it into excel from SQL. So yeah, any ideas would be super, a pivot table being a last resort.
Thanks.

Assuming your source data range is on Sheet1, from A1 to C3 and your results range is on Sheet2, from A1 to D4.
You can put this formula on B2:
=SUMPRODUCT((Sheet1!$A$1:$A$3=Sheet2!B$1)*(Sheet1!$B$1:$B$3=Sheet2!$A2)*Sheet1!$C$1:$C$3)
and then, drag and drop this formula on the whole range.

Why don't you create a third column that combines the values from columns A and B using =A1&B1 and then do vlookup on that value:
A B C D
ID1 ID2 ID1ID2 0.5
ID1 ID3 ID1ID3 0.7
ID2 ID3 ID2ID3 0.9

Related

maxifs returning 00/00/1900 as date for blank date

I want latest dates corresponding to each unique ID mentioned in sheet1. When no date is mentioned against an ID , I am getting 00/01/1900 as the latest date instead of blank. How to fix this
Sheet1 (input data sheet)
A B
2 ID Date1
3 ID1 20/11/2020
4 ID2 18/10/2019
5 ID1 29/01/2018
6 ID2 10/10/2021
7 ID3
Formula used in sheet2 (to caluclate latest date for each ID)
A B
2 IDSheet2 Latestdate
3 ID2 =maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)
4 ID1
5 ID3
OUTPUT obtained
A B
2 IDSheet2 Latestdate
3 ID2 10/10/2021
4 ID1 20/11/2020
5 ID3 00/01/1900 (want a blank here)
Issue:
I am getting 00/01/1900 as date when there is a blank date corresponding to an ID. How to get blank against ID3 here for instance instead of 00/01/1900
Two current options:
IF formula
This lets you check if the max would be 0
=IF(MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2)=0, "", MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2))
Cell formatting
On the relevant cells, change cell formatting (CTRL+1), choose custom and enter dd/mm/yyyy;;
Doing this requires no formula change.
(bonus for future Excel release - IF with LET)
In an upcoming release there will be the LET function where you only define the variable once for improved performance and easier reading. The formula would be: =LET(max_value,MAXIFS(Sheet1!B:B,Sheet1!$A:$A,A2),IF(max_value=0,"",max_value))
use the reciprocal or the reciprocal:
=IFERROR(1/(1/maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)),"")
Try it
if(day(maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2)<1,"",maxifs('Sheet1'!B:B,'Sheet1'!$A:$A,"="&A2))

Find the corresponding value in a separate table depending on another table in Excel

I am trying to find the value in one table (Table 2), based on the location of a "Yes" in another table (Table 1). See below:
Table 1
Header1 Unique1 Unique2 Unique3
Row1 Yes
Row2 Yes
Row3 Yes
Table 2
Header1 Unique1 Unique2 Unique3
Row1 XXX
Row2 YYY
Row3 ZZZ
On another sheet, I have a column with "Unique1" or "Unique2" as follows and am trying to get the column that is labeled "Lookup":
Column1 Lookup
Unique1 XXX
Unique1 XXX
Unique3 ZZZ
Unique2 YYY
I am glad you got it working. I actually did manage to cram it into one formula.=INDEX(Sheet1!$A$5:$D$8,MATCH("Yes",INDIRECT("Sheet1!"&CHAR(CODE("A")+MATCH($A2,Sheet1!$1:$1,0)-1)&":"&CHAR(CODE("A")+MATCH($A2,Sheet1!$1:$1,0)-1)),0),MATCH($A2,Sheet1!$1:$1,0))
The way that works is it goes into your table 2 and picks out a row and a column. The column is whichever holds the name. The row gets constructed by looking for yes in the appropriate column. To name that column with a letter and not a number, I needed to convert with the whole CHAR CODE thing.

excel multiple column vlookup

My table
Id index Col1 col2 col3
a 1 smith
a 2 John
b 1 mark
b 2 kay
b 3 Van
c 1 Par
c 2 Cap
In the Vlookup Table
ID Col1 Col2 Col3
a Smith John
b Mark kay Van
c Par Cap
How do I achieve by doing vlookup by id
I believe this will solve your issue:
This is the formula in cell I2:
=INDEX($C:$C,MATCH($H2,$A:$A,0))
This is the formula in cell J2:
=IF(INDEX($D:$D,MATCH($H2,$A:$A,0))=0,OFFSET(INDEX($D:$D,MATCH($H2,$A:$A,0)),1,0))
This is the formula in cell K2:
=IF(INDEX($E:$E,MATCH($H2,$A:$A,0))=0,OFFSET(INDEX($E:$E,MATCH($H2,$A:$A,0)),2,0))
Hope this helps!
Thanks.
If you want to use vlookup instead of index and match, you could use a helper column:
The formula in cell 1 is:
=B2&C2
The formula in cell H2 is:
=IF(ISERROR(VLOOKUP($H2&RIGHT(I$1,1),$A$2:$C$8,RIGHT(I$1,1),0)),0,VLOOKUP($H2&RIGHT(I$1,1),$A$1:$F$8,RIGHT(I$1,1)+3,0))
To make the formula be the same in all cells in the output table, I have used the rightmost character in the column name as an index. Hard coding this value, or adding a helper row, would make it easier to read.

Find Gene name in Column A and put the given ID in column B

I have an excel Sheet with 2 columns, in this form
ADRBK2 NA
ADRBK2 NA
A1CF ID1
A2M ID2
ADRBK2 NA
Now what I want to achieve is that i look up the gene ADRBK2 in Column A and where ever i find this gene in Column A in my file, I want to put ID3 at the column B next to it. How can i Achieve this ?
Sort your data alphabetically, put ID3 in cell next to first ADRBK2, drag by left bottom corner of the ADRBK2 cell to the end of empty cells(simple copy).

Remove swapped duplicated row using Excel

I have an id pairs in 2 columns. There are some pairs which are redundant, but in a swapped form. How can i removed redundant id pairs using Excel?
Here is the explanation,
Initial,
col1 col2
id1 id2
id2 id1
id3 id8
id1 id5
id1 id6
id2 id9
Need to be like,
col1 col2
id1 id2
id3 id8
id1 id5
id1 id6
id2 id9
(Note that the 2nd row id2 id1 is deleted, because it is a swapped duplicate).
Thanks..
1.Write two max min functions in the as a excel function adjacent to these 2 cells(maxa did not work for some reason)
2.copy values only to some other place and remove duplicates.
ps: I tried to transpose then sort transpose back, but it tries to sort as one big record rather than tuples. Hence the function.
I would use the following steps:-
Join them together in the right order into column C
=IF(A2<B2,A2&"|"&B2,B2&"|"&A2)
Find the unique values in column D (array formula must be entered with Ctrl-Shift-Enter))
=IFERROR(INDEX($C$2:$C$7, MATCH(0, COUNTIF($D$1:D1, $C$2:$C$7), 0)),"")
Separate the first one in Column E
=IFERROR(LEFT(D2,FIND("|",D2)-1),"")
Separate the second one in column F
=IFERROR(RIGHT(D2,LEN(D2)-FIND("|",D2)),"")
Assuming you're dealing with Column A and B with a header in each column, I'd do this put cell C2 and drag down. Delete anything greater than 0:
=COUNTIFS($B$2:B2,A2,$A$2:A2,B2)
To clarify what's happening here, the $ in the ranges act as anchors when you drag down. So making the range from $B$2:B2 means the next cell down will be $B$2:B3 followed by $B$2:B4 and so on.
The COUNTIFS() formula returns a count where ALL the criteria are met, so only those rows with both values switched are counted.
Using the COUNTIFS() with the anchored range like I've done here only counts whatever comes above that row, which is why you can delete any non-zeros without losing the unique values.
I'd recommend verifying this in case there's something I didn't think of, of course.

Resources