HOWTO ad a unique id to each unique row? - excel

I have data in two columns:
a 1
a 1
a 2
b 3
b 4
In the list there is 4 unique rows. I would like to ad a unique id to each unique row.
Like this:
1 a 1
1 a 1
2 a 2
3 b 3
4 b 4
Of course I have many more rows and columns and date are more complex than in this example.
Anyway to do this i excel?
Mvh Kresten Buch

I have the same issue, I have developed a three formula approach to this. I could probably concatenate it if I nested them, but whatevs, this works.
Assume the data you want to 'number' is in column A, and the first row of the table is row 3.
The first column (in column B) counts occurrences of the 'value' and the range expands from the top of the table downwards as the table grows:
=COUNTIF($A$3:A3,A3)
the second column's formula also expands as the row count does, and simply adds 1 to the transaction count every time it encounters a 1 (ie first occurrence of a new unique value) in column B
=IF(B3=1,MAX($C$2:C2)+1,"")
This one worked for me even in the first row of the table btw - i was expecting to have to manually input a 1 to start the list. Having it work without the manual entry is a good thing, it means the formmulas all work even if you resort the table data into a different order.
The third one in column D uses a vlookup to find the value. Note that when vlookup finds more than one number, it always pulls the first occurrence.
=VLOOKUP(A3,$A$3:C3,3,FALSE)
Note that this will renumber all the data outcomes dynamically if you do resort the entire thing. ie the formulas all work, but the number 'assigned' to a praticular set of data might be different, as it all works from whatever order the list of items is in.
My use case for these formulas assumes that every month i paste a new set of data to the bottom of the table, some items of which are repeats from previous months - ie are already in the table, and some of which are new.
if the dynamic renumbering is a problem, use a 'row key' so you can resort back to the original order at the end.

Assuming your data is in B2:C6 please try =IF(AND(B1=B2,C1=C2),A1,A1+1) in A2, copied down

If your data is not sorted, it's more complicated... but you can use something like this in A2:
=IF(COUNTIFS($B$1:B2,B2,$C$1:C2,C2)>1,INDEX($A$1:A1,IFERROR(MATCH(B2&"-"&C2,$B$1:B1&"-"&$C$1:C1,0),1)),MAX($A$1:A1)+1)
I'm assuming that there are no headers and you have already put 1 in cell A1 for the first record.
It basically checks the whole columns above the formula and if there's already a similar record, it'll assign the previously given unique ID and if not, it'll give a new ID.
This is an array function and as such will work if you use Ctrl+Shift+Enter and not Enter alone.
The IFERROR() is there because MATCH(B2&"-"&C2,$B$1:B1&"-"&$C$1:C1,0) would return an error if it is on row 2 (the first record to check).
Once you put that in the first cell, you can fill down the formula.

I deal with this issue all the time when structuring a data set into panel data. say you have multiple columns of data, and each are unique based on the name of someone, like:
ANNE
ROSE
ANNE
FRANK
TOM
ROSE
ANNE
but instead of having each column related to Anne, Rose, Frank, or Tom, you want it to look like this:
1 ANNE
2 ROSE
1 ANNE
3 FRANK
4 TOM
2 ROSE
1 ANNE
So that each name now has a unique numerical identifier that can be used in place of the name.
Make a pivot table of your data and only place the column that has the names (or whatever the identifier may be) into the Rows section. This will single out all the different names used within the dataset. Copy and paste this pivot table anywhere on the sheet so that the names are in actual cells and not off of a pivot table. To the right of the names, enter 1 next to the first name, and then =B1+1, and so on so that you number each name with a unique value; then copy and paste this column as numbers so that their formulas are erased. Finally, just go to your original dataset and perform a VLOOKUP so that the names get attached with whatever unique value was assigned off of the pivot table. Make sure to copy and paste as numbers once done to remove the VLOOKUP formula.
Takes literally 2 minutes to do, depending on size of dataset, and is very easy. It will work perfectly every time.

Related

How to search on multiple columns in ecxel "vlookup" and return value from another column in the same row?

I have an excel file.
Its purpose is to have a list of rooms (working rooms), and people names, so I can know TWO things:
Who is embedded in each room.
What is the room of a specific person.
The file has 2 spreadsheets in it.
The first one (called “people”) is a list of names, with another column which says what is the room of each person. Note: There are NOT two identical names. Every name is different.
The second one (called “rooms”) is a list of 5 columns:
the first column is the room number
the other 4, are 4 names of people (because each room has 4 people in it). Note: the order of the people in the room (in the 4 columns) is not important.
The problem starts when I want to swap 2 people from different rooms. Then, I have to change it in both spreadsheets.
I want to find a formula that finds a name in “rooms” spreadsheet, and writes the room number (column A) in the correct row in “people” spreadsheet in column B.
I have tried to use one of the lookup formulas (and especially vlookup) but the problem is the fact that those functions search only in the first column and return value from the other columns, whereas I need exactly the opposite: I want to find value (specific name) from one of the 4 columns, and return the value of the first column (the room number - column A). That way I can go to B column in “people” spreadsheet, and insert a formula for each name in it, so it can find the correct room number.
Another problem is the fact that the room numbers in “rooms” spreadsheet are not necessarily sorted. Sometimes I want to take a group and move it to a different room. In this case, all I do is changing the room number in column A, thing that makes the list to be not-sorted.
How can I do this with a formula, in a way that I will need to change only the people in "rooms" spreadsheet, and not to change room number in "people" spreadsheet? Is there a formula that does what I need, or should I use more than one formula to achieve my goal?
Using INDEX & AGGREGATE Function
• Formula used in cell B4
=INDEX(rooms!$A$4:$A$8,AGGREGATE(15,6,(ROW(rooms!$B$4:$E$8)-ROW(rooms!$B$4)+1)/(people!$A4=rooms!$B$4:$E$8),1))
So let me explain how AGGREGATE() Function returns the position of each emp, actually it returns the row number in which emp falls in
AGGREGATE(15,6,(ROW(rooms!$B$4:$E$8)-ROW(rooms!$B$4)+1)/(people!$A4=rooms!$B$4:$E$8),1)
Next when wrapped within an INDEX() Function it outputs the Room Numbers as desired.
Refer the image below, when altered !
Formula in column B is:
=INDEX($B$3:$B$7;SUMPRODUCT(--($C$3:$F$7=A12)*ROW($B$3:$B$7))-2)
Notice the -2 at the end. This is because data starts at row 3 so we need to adjust.
IF we swap 2 names (name 7 and 8) or 2 complete rooms (rooms 1 and 5) the results will autoupdate:
For Excel365; using LET for readability and alterability you can use:
=LET(data, rooms!B4:E8, index, MIN(IF(data=A4, ROW(data)+1))-ROW(INDEX(data,1,1)), INDEX(rooms!A4:A8, index))
Otherwise:
=INDEX(rooms!A4:A8,MIN(IF(rooms!B4:E8=A4,ROW(rooms!B4:E8)-3)))

Getting Top Values from One Sheet and inputting onto a different sheet

So I'm going to eventually have 3 sheets. Sheet 1 is where I have data (numbers for a category and a name associated with it. Sheet 2 is where I pull the top 5 users for each category. Sheet 3 is where I have a leaderboard for points gained.
Right now I'm trying to work with Sheet 2 (grab the top 5 performers from each category. I'm fairly new to Excel, but after some research it seemed that XLOOKUP would be the way to go. (i'll attach screenshots below.
I'm using this formula:
=XLOOKUP(LARGE('Cases Test for Categories'!$C$18:$C$55,1),'Cases Test for Categories'!$C$18:$C$55,'Cases Test for Categories'!$A$18:$A$55)
however when using it I get all 0's.
Here's a screenshot of values I'm trying to grab from "Warranty Service Request"
and here is a screenshot when applying my formula
The solution I would want is to grab the 5 largest numbers from sheet 1 with the person name as well.
I don't think that XLOOKUP can get you anywhere near what you want but the formula below will get you one step closer.
=INDEX(List,MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0),1)
In fact, it's the explanation of that formula which will be of help. Here we go.
List is a named range, perhaps equal to your 'Cases Test for Categories'!$C$18:$C$55. The reason for using a name is obvious. It's shorter. In my test List = A2:B6, in case you want to reconstruct it. Column 1 has names, column 2 numbers.
The term INDEX(List,,2) specifies the second column of List. You can replace the '2' with a formula to specify different columns of the named range.
In fact, INDEX(List,,1) does specify the first column and INDEX(List,4,1) specifies the 4th cell in that column, and that is exactly what you see in my formula. All of MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0) just serves to find the row number in List, in this example the number 4.
Of course, LARGE(INDEX(List, ,2),1) returns the largest number in column2 of List. The '1' can be replaced by a formula, for example ROW()-1 which would return 1 if placed in row 2 and count up from there as it's copied down. Try =ROW()-1 in any cell in row 2 and copy the formula down.
MATCH([LARGEST],INDEX(List,,2),0) returns the row number where the largest was found, and that is the number we need to return the name from the first column of List.
This will work perfectly for one column and can easily be modified to work for different columns. Your question doesn't specify how you would like to arrange the 5 results from each category but the formula can be modified a little to accommodate whatever you want. What it can not do is to deal with ties. MATCH(LARGE can only find the first of several identical results.
To break ties in this sort of operation is complicated and must be done ether by helper columns in the data table or using VBA. It's definitely the topic of another question. For now I hope that it's a problem you will not have to anticipate.

Searching two excel columns for occurrence of two strings together

I'm looking for a way to count the number of times two cells appear side by side in Excel - like intersections. Sometimes in my data (of about 550 records) A Road will appear next to B Road, which is a count of 1. If it occurs again, later in the data the count would be 2. But if B Road appears in the first column and A Road appears in the second column, I can't find a way to make that number 3 in the count.
I've tried concatenating the data, but I need to be able to write this formula without inserting specific criteria (like searching for A Road) because it would be easier in that case to do this manually. Does anyone know if there's a formula for find the occurrence of the same two variables between two columns without specific criteria?
If the order of values in the two columns were important (i.e. A Road followed by B Road is different than B Road followed by A Road), then a simple pivot table would provide the counts you need. You would just put Col M on the rows, Col N on the columns and the count of any field as the value.
But the OP has said that A Road followed by B Road should be counted in the same total as B Road followed by A Road. Let's modify the concatenation in Col O to become =IF(M2<N2,CONCAT(M2," & ",N2),CONCAT(N2," & ",M2)). That provides a canonical form of each combination regardless of order. Having done that, then it is again an easy matter to create a pivot table that shows all the required counts -- just put the concatenated value on the rows and the count as the value.
If I correctly understand your intent, then try this array formula : =SUM(IF(EXACT(B$2:B3&C$2:C3,B3&C3),1,""))+SUM(IF(EXACT(B$2:B3&C$2:C3,C3&B3),1,"")).The second sum formula accounts for any reverse order of adjacent street occurrences.Then copy down the column as needed. Enter with Ctrl+Shift+Enter.

Removing opposites from Excel

I am trying to figure out a way to remove values that have a net result of zero. For example I have data that is 10,000 and -10,000. They are linked to the same person though not the only transaction linked to a single individual.
Is there a method to remove both of these rows from my Excel document?
Here is a the kind of data I'm looking at
And I want to remove all but the last row as it is the only unique one.
If you create a helper column with =ABS(A1) copied down and then sort on ColumnB, that helper column and within that on ColumnA - you should end up with sets as you already have pairs. Then in another helper column Row2 and copied down:
=IF(OR(A1=-A2,A2=-A3),"#","")
should flag 'equal and opposites' next to one another. Remove those and repeat until no more flags appear, if you have multiple instances of equal and opposite values. Beware however where the last value for one Cust # is equal and opposite to the first value of the next Cust #.

assigning a value based on another column in Excel

I am trying to find a quick way to assign a value for a column depending on the value of another.I want to increase the value of column A by one each time the value of column B changes.
Column A Column B
1 (520)998-7765
1 (520)998-7765
1 (520)998-7765
2 (450)877-4563
2 (450)877-4563
2 (450)877-4563
2 (450)877-4563
3 (650)989-7654
3 (650)989-7654
3 (650)989-7654
.... ....
I need to know if there is a formula that I can use to sort through 27,000 lines of data rather than assigning them one by one.
I am using a phone number as a unique identifier and I want the ID# to increase by one every time the phone number changes.
Please Help!!
Put value "1" in A2.
In A3 and after put the following function
=IF(B3=B2,A2,A2+1)
EDIT
You can make a single formula for all of the rows.
Put something like this in A2 and copy it down:
=IF(ROW(A2)=2,1,IF(B2=B1,A1,A1+1))
It seems like you are trying to extract the unique list of phone numbers? If so, there is a Remove Duplicates function in Excel (under the Data tab) that should do what you need.
You would select your full range (27,000 phone numbers) and run Remove Duplicates. Excel would then leave behind a single row for each unique number.
I believe Remove Duplicates is available for Excel 2007 or later.
If you are using an older version of Excel, here is a link that gives more information on filtering for a unique list:
Count unique values among duplicates

Resources