Use Excel to look for 2 string values over 2 columns and in one row and return the cell value if there is a match on either of the lookup strings - excel-formula

I would like to have some help with creating an MS Excel 2013 formula that would do the following.
It should look for two string values over 2 columns in one row and should return the cell value of the cell in which the string value was found.
Sorry if I am not explaining myself correctly. Here is an example of the dataset and my expected result
My Dataset have 2 columns A and B but I would like only 1 output in C if ocn OR ocm exist.
I would like to use this formula to normalise this data set.
A B C (Result for ocm or ocn)
(OCoLC)911180191 (OCoLC)ocn911180191 (OCoLC)ocn911180191
(OCoLC)ocn911180196 (OCoLC)911180196 (OCoLC)ocn911180196
(OCoLC)911495338 (OCoLC)ocm911495338 (OCoLC)ocm911495338
(OCoLC)ocm794701569 (OCoLC)794701569 (OCoLC)ocm794701569
Click to see a picture of what I am trying to do

In C2 Cell
=IF(SUM(COUNTIF(A2,{"*ocn*","*ocm*"})),A2,IF(SUM(COUNTIF(B2,{"*ocn*","*ocm*"})),B2,""))
Or
=IFERROR(LOOKUP(2,1/MATCH({"*ocn*","*ocm*"},A2:B2,0),A2:B2),"")
Or
=IFERROR(LOOKUP(2,1/SEARCH({"*ocn*","*ocm*"},A2:B2),A2:B2),"")
Or
=IF(SUMPRODUCT(--ISNUMBER(SEARCH({"*ocn*","*ocm*"},A2))),A2,IF(SUMPRODUCT(--ISNUMBER(SEARCH({"*ocn*","*ocm*"},B2))),B2,""))
Drag the C2 Cell formula down.

Related

Number occurrences in another cell (Excell) [duplicate]

I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)

Formula to Return Text in the Row of Largest Number

Column A Has Text & Columns B, C & D contain numbers.
For Ex.)
A... …B C D
John 4 6 2
Dave 4 6 4
Mike 4 5 1
Bill 2 5 9
I would like a cell to return the name in column A that has the Largest Number in Column B. And if there are similar numbers, go to the next column and determine which is highest, and if that is tied go to the next column and so on.
Any help would be appreciated.
We can de-conflict ties.In E1 enter:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))
and copy down. Then in another cell enter:
=INDEX(A:A,MATCH(MAX(E:E),E:E,0))
EDIT#1
This is only good for 3 columns of numbers, but it is very easy to add additional de-confliction terms if necessary:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))+E1/(1000*MAX(E:E))
For an expandable number of rows/columns, use a helper row with the same number of columns as number columns in your data. The formulas below reference the following image (the data are in A1:G7):
B9-->=MAX(B1:B7)
C9 (fill over the remaining columns to G9)-->
=MAX(IF(MMULT(--($B1:B7=$B9:B9),--(ROW(INDIRECT("1:"&COLUMNS($B9:B9)))>0))=COLUMNS($B9:B9),C1:C7))
The following formula will give the answer (shown in A9 above):
=INDEX(A1:A7,MATCH(TRUE,(MMULT(--($B1:G7=$B9:G9),--(ROW(INDIRECT("1:"&COLUMNS($B9:G9)))>0))=COLUMNS($B9:G9)),0))
UPDATE WITH ALTERNATIVE METHOD
Using a helper column instead, again referencing the image below (the data are in A1:G7):
I1 (fill down to I7)-->
=SUM(--(MMULT(SIGN(B1:G1-$B$1:$G$7)*2^(COLUMN(G1)-COLUMN(A1:F1)),--(ROW(INDIRECT("1:"&COLUMNS(B1:G1)))>0))>0))
The following formula will give the answer (shown in J1 above):
=INDEX(A1:A7,MATCH(MAX(I1:I7),I1:I7,))
As a bonus, notice that the helper column corresponds to the order that you would get from sorting the data by each column left-to-right. In other words, you could use the helper column to perform a formula-based multi-column sort on strictly numeric data. For the last image, entering the following array formula into a range with the same dimensions as A1:G7 gives a descending sort on columns B through G:
=IF(A1:A7=A1:A7,INDEX(A1:G7,MATCH(ROW(A7)-ROW(A1:A7),I1:I7,0),))

Calculate Occurrence Number - Excel

I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)

Count with criteria for changing column in excel

I have a data looks like this:
a b c
1 3 4
2 3 3
4 1 2
2 4 2
In another worksheet, I want to do the following calculation:
whenever A1 returns a (header of data worksheet), count number of items that are smaller and equal to 2 in column "a". (result will be 2)
if A1 returns b, count number of items that are smaller and equal to 2 in column "b". (result will be 1).
A1 has already been preset with formula such that it will show a or b or c as conditions changed.
I need the formula to be lean... I actually have 6 headers, so if I keep on using if functions, I will probably have to set 6 if functions in one cell...that can be overwhelming. index match cannot provide a range to work on...Any suggestion? thanks
I don't know vba. If you could provide a workable vba code, i don't mind. but i don't know how to read it...>.< please provide user manual for that. lol, thank you~
If your data is found on Sheet1 and the a is found on column a, b is found on column b etc. enter this formula on then next sheet on b1 when a1 is the column value:
=COUNTIF(INDIRECT("Sheet1!"&a1&":"&a1),"<=2")
The Indirect is for adding text to your reference.
If your data sheet is Sheet1, you could try the array formula:-
=SUM((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Must be entered with CtrlShiftEnter
(actually there are 3 items less than or equal to 2 in column A)
Or you can use the SUMPRODUCT version if you prefer not to use an array formula:-
=SUMPRODUCT((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Or you can use this INDEX/MATCH method which is probably more efficient:-
=COUNTIF(INDEX(Sheet1!A2:C5,,MATCH(A1,Sheet1!A1:C1,0)),"<="&2)

Excel vlookup with two columns in source and target returning another column

I have a spreadsheet that has 4 columns sheet 1, and 5 columns sheet2 and I need to do a vlookup on Sheet1!a2&c2 and match the row in sheet2!a2&c2 and return sheet2!c5.
I think Index and Match would do it but all the examples have been matching a single value to an array which isn't what I need for eg.
Can't do attachments yet :( text it is sorry for the format
Sheet1
R1 A B C D
R2 2 D 3 Result will match sheet1!a2&c2 to sheet 2!A3&C3 and return Sheet2!e3 ie 34
Sheet2
R1 A B C D E
R2 2 F 5 GR 72
R3 2 X 3 FR 34
Any links or help?
Update
Sorry I wasn't clear I want to match the cobination of A2 and C2 in sheet 1,
ie in the example =sheet1!A2&sheet1!c2=23
to the values in sheet2!a2 plus sheet2!c2,
ie in this example =Sheet2!a3&Sheet2!c3=23,
and then return the value in Sheet2!E? , ie Sheet2!E3=34 here
I've done this before by creating a cheat column in sheet 2 = a2&c2 in say d2 and filling down then using, assuming 3 rows, however I can't create the cheat column in sheet2
=vlookup(a2&c2,sheet2!d2:e3, 2, false)
The rows sheet2! look like, sorry about the formatting
Picture attached, which I suddenly got to do , where I need to match the yellow columns in the lookup then return the brown column to sheet1!E2 but I can't add the cheat column Sheet2!d2:3 to the sheet cause the user is difficult :)
Thanks again. Any good tutorial on Index?
Try using LOOKUP like this
=LOOKUP(2,1/(A2=Sheet2!A$2:A$10)/(C2=Sheet2!C$2:C$10),Sheet2!E$2:E$10)
The two "tests", i.e.
(A2=Sheet2!A$2:A$10)
and
(C2=Sheet2!C$2:C$10)
return "arrays" of TRUE/FALSE values but when you divide 1 by one of those and then the other TRUE is converted to 1 and FALSE to 0 so you get a resulting array of either 1s (where both conditions are TRUE) or errors [#DIV/0!] where one or both are FALSE.
When you lookup 2 in that array it will never be found so it matches with the last 1, i.e. the match is with the last row where both conditions are satisfied...and the corresponding value from Sheet2!E$2:E$10 is returned. Another way is like this:
=INDEX(Sheet2!E$2:E$10,MATCH(1,(A2=Sheet2!A$2:A$10)*(C2=Sheet2!C$2:C$10),0))
which requires "array entry" with CTRL+SHIFT+ENTER

Resources