In Excel I want to delete duplicate rows but I want to have some preferences for what duplicate occurrence to keep. As in Excel while removing duplicates it by default keeps the first occurrence. Is there any way to keep the 2nd or 3rd occurrence?
For example:
a Apple
a Banana
a Cherry
b Apple
b Banana
b Melon
c Apple
c Cherry
c Melon
By default if I remove duplicate, it would be like this:
a Apple
b Apple
c Apple
But is there a way to achieve this
a Banana
b Banana
c ?
As the C doesn't have banana, we can keep this blank, or any default value.
To always keep the second occurrence,
SORT the data,
MATCH the elements among itself to get the first occurrence,
Subtract the matched row number from actual row number and if it's not 1, filter it out.
Input:
Duplicates
Helper column
a
Apple
a
Cherry
b
Apple
c
Apple
c
Cherry
b
Banana
b
Melon
a
Banana
c
Melon
Formula:
=FILTER(SORT(A1:B9,1,1),ROW(A1:A9)-MATCH(SORT(A1:A9),SORT(A1:A9),0)=1)
Output:
Second occurrence
Helper column
a
Cherry
b
Banana
c
Cherry
see:
=FILTER(A1:B, COUNTIFS(A1:A, A1:A, ROW(A1:A), "<="&ROW(A1:A))=2)
for 3rd occurrence change 2 to 3
Related
What if I have 4 columns with data, and want the value that is more than once in those 4 columns(A-B-C-D).
apple pear melon grape
melon apple melon grape
pear melon melon pear
My list in column E is;
``
apple
pear
melon
grape
And what I would like is that in column F the value appears of the fruit that is more than once in a row.
So F1 should return nothing, F2 should return "melon", and F3 should return "pear, melon"
Is that posible with a formula?
Try,
In B1, array ("Ctrl"+Shift"+"Enter") formula copied down :
=MID(TEXTJOIN(", ",,FILTERXML("<a>A<b>"&SUBSTITUTE(TRIM(A1)," ","</b><b>")&"</b></a>","a|a/b[not(preceding::* =.)][following::* =.]")),4,999)
Remark : If you have Office 365, the above formula is normal entry.
If source data put in separated cells, then formula become >>
In F1, array ("Ctrl"+Shift"+"Enter") formula copied down :
=MID(TEXTJOIN(", ",,FILTERXML("<a>A<b>"&TEXTJOIN("</b><b>",,A1:D1)&"</b></a>","a|a/b[not(preceding::* =.)][following::* =.]")),4,999)
Remark : If you have Office 365, the above formula is also normal entry.
I've got a problem with an excel sheet with 4 columns where two columns rely on each other because Column A is the name and column B is the quantity, the same thing with columns C and D.
Table
==========================================
A B C D
Apple 54 Banana 12
Peanut 6 Pineapple 4
Cranberry 112 Cherry 40
Cookie 3 Peanut 4
Banana 2 Cranberry 5
Peach 3 Almond 10
Cherry 5
Cheese 10
What I want to get is that each content of column C with the quantity in column D will be placed in the same row as their matching part in column A so I can compare the quantities between B and D. All the values with no matching partner should be placed at the bottom or just with an empty table, so I know there is no match.
Example how it should look like:
Table
==========================================
A B C D
Apple 54
Peanut 6 Peanut 4
Cranberry 112 Cranberry 5
Cookie 3
Banana 2 Banana 12
Peach 3
Cherry 5 Cherry 40
Cheese 10
Almond 10
Pineapple 4
This should solve your problem: =VLOOKUP(C2;$A$2:$B$9;2;TRUE)
You simply add this as a column "E" in your spreadsheet and drag it down then you can compare the values.
Col A remains as it is.
Col B remains as it is.
Col C moves to Col E.
Col D moves to Col F.
New Col C, Cell C1 = =IFS(AND(A1<>"",(COUNTIF($E$1:E, A1)=1)=TRUE),A1,AND(A1<>"",(COUNTIF($E$1:E, A1)=1)=FALSE),"",A1="",ArrayFormula(INDEX($E$1:E,SMALL(IF(ISERROR(MATCH($E$1:E,$A$1:A,0)),(ROW($E$1:E)-MIN(ROW($A$1:A))+1),""),SUM(ROW(1:1)-COUNTA($A$1:A1))))))
Copy this down from C1
New Col D, Cell D1 = =IF(C1="","",VLOOKUP(C1,$E$1:F,2,FALSE))
Note: I wrote this in Google sheets, So when I type ctrl + shift + enter it coverts it into ArrayFormula(). You will need to do an array formula the excel way - ctrl + shift + enter and remove the ArrayFormula().
Feel free to view this in a sheet - https://docs.google.com/spreadsheets/d/10hygbPyzj7L1u77izejoeGriaquoZ_omp49pCJ2U7uE/edit?usp=sharing
If you want to export the sheet. Right click the "sheet 1" tab, go to "copy to" and "new spreadsheet"
Any questions, let me know :)
I have a column (column A) that contains a list of text and another column (column B) that contains a smaller list, which is the values that I actually care about. Is it possible to only highlight cells in column A if all of its contents is listed in column B? If so, how?
A B
Apple Apple
Peach Pear
Apple, Pear Plum
Apple, Grape Kiwi
Apple, Pear, Kiwi
Watermelon, Grape
So in the above example, I would like to highlight A1, A3, and A5 because all of the contents is listed somewhere in column B
use the following formula for the Conditional formatting:
=AND(ISNUMBER(MATCH(FILTERXML("<a><b>"&SUBSTITUTE($A1,",","</b><b>")&"</b></a>","//b"),$B:$B,0)))
If one does not have FILTERXML then they can use:
=SUMPRODUCT(--ISNUMBER(SEARCH("," &$B$1:$B$4&",",","&SUBSTITUTE(A1," ","")&",")))=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1
Noting that the range $B$1:$B$4 must be the size of the lookup values without any blanks
I'm not even sure if what i want to happen is possible but here it is :
So i have a list on column A and another on column B. Say, column A has apples, bananas, eggs... Then column B has apple pies, banana pies, egg pies...on column C, I want excel to tell me that apples and apple pies match and bananas and banana pies match, and so on. Then tell me if they don't match at all. I want it so that even if i want 2 values from column A to match with a value in column B. For example aside from apples there could also be pears in column A but i would still want pears to return a match value with apple pies. I hope this is not too confusing
... Thanks in advance!
Ok, I am going to give you multiple answers because I am not sure what the question is. If Gary's Student's comment is the right answer and you just want to match the contents then all you need to do is put this in C2 and copy it to every row:
=IF(ISERROR(FIND(A2,B2)),"no match","match")
But if your comment about 1-2=bad, 3-8=good and 9-10=very good is what you really want then all you need to do is put this in C2 and copy it to every row:
=IF(B2=CHOOSE(A2,"bad","bad","good","good","good","good","good","good","very good","very good"),"match","no match")
What that does is change the number in column A to be the equivalent string and then match that string against column B.
But if you are looking for a solution that works for both things then you need a dictionary. If you use ALL the piossible values from B as the keys and each matching value from A as the values then you can call MATCH twice and see if the value belongs to the key.
So for example the dictionary for the pie example might look like this (notice that pies can have more than one ingredient):
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 lemon pie lemon egg
3 apple pie apple pear
4 pear pie pear
5 egg pie egg
And the dictionary for the bad and good example would look like:
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 bad 1 2
3 good 3 4 5 6 7 8
4 very good 9 10
Then you can stick this in C2 and copy it to every row:
=IF(ISNA(MATCH(A2,OFFSET(F$1:O$1,MATCH(B2,E$2:E$20,0),0),0)),"no match","match")
What this does is look up the value in column B in the dictionary and find what row it is in. Then it offsets F$1:O$1 by that many rows so that the range for the outside match is the correct list of incgredients. Then it matches the value in column A by the list of ingredients that the offseted inside match produced.
Maybe some screenshots will help:
What is the formula that we can use in Microsoft Excel to get the result of the value summation from string column A and string Column C if they are the same? Column B and Column D are both the number that assign to its respective column which is Column A and Column C. For example “orange” holds the value 6 (in Column B) for Column A while in Column C “orange” hold the value 2 (in column D).Final results should show the summation of 6+2=8 (in Column F) for string ‘Orange’ (Column E).
Thank you
Lupe
If you have this table:
A B C D
orange 1 orange 6
apple 2 apple 7
grapes 3 carrot 8
carrot 4 melon 9
And you want to search in column C for each of the A column values, you should use this in column E: (for E2, and drag down)
=IFERROR($B2+VLOOKUP($A2,$C$2:$D$5,2,FALSE), 0)
make sure to change $C$2:$D$5 to your range (in both places).
A B C D E
orange 1 orange 6 7
apple 2 apple 7 9
grapes 3 carrot 8 0
carrot 4 melon 9 12