Need help in generating a formula for nextID excel column - excel

I have a an excel sheet with the following columns
ID, City, Record no.
I need to generate a column called Next ID based on the record number.
i.e if the city is same I need to populate the Next ID column with the ID of the previous record number.
Is there a way to do this in excel?
Here is the sample data, with the Next Column populated manually for reference:
ID City Record no. **Next ID
121 Paris 3
122 Paris 2 121
123 Paris 1 122
124 New York 2
125 New York 1 124
Please see attached image
I've edit the question as I was not able to add a image in the comments. My data is not sorted so I used the second formula. This works for some cases but doesn't work for others. see the pink colored cells which should have a value but do not.

If your data is always sorted use this:
=IF(B2=B1,A1,"")
in D2 and copy/drag down
If not sorted then use this:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($C$2:$C$6)/(($C$2:$C$6=C2+1)*($B$2:$B$6=B2)),1)),"")

Related

How to copy a column from one sheet to another in MS- Excel, with ID as reference

I have 2 sheets in one excel file. I'd like to copy only the team column from sheet 2 to sheet 1. Both sheets have matching ID to relate to each other.
Sheet 1
id
name
address
team
123
Paul
1st street
456
Kyle
2nd Street
Sheet 2
id
name
team
123
Paul
CL
456
Kyle
BSM
And then sheet 1 will now look like this:
id
name
address
team
123
Paul
1st street
CL
456
Kyle
2nd Street
BSM
I don't know where to start. I know though that this can be done in excel, and you can do programming on it. I don't want to manually input it since it's more than a hundred records.
Okay so I am assuming all the headers are in first row. This can easily be done through Vlookup
=VLOOKUP(A2,Sheet2!A:C,3,FALSE)
Put this formula in column team in Sheet1. It will work.
Let me know if you need any further clarification.

Selecting rows of a table from a column of another table

I have a column in "table1.xlsx" with more than 200 IDs.
ID
21321
54646
48949
...
And another "table2.xlsx" with the IDs plus all the information about the people.
Name Surname ID City
John Wayne 54646 Madrid
Mary Jane 11111 Berlin
Julius Randle 21321 Rome
Peter Parker 48949 New York
I would like to extract the rows from "table2" that match with the IDs from "table1". There is an easy way?
"table3.xlsx"
Name Surname ID City
John Wayne 54646 Madrid
Julius Randle 21321 Rome
Peter Parker 48949 New York
Open table1.xlsx, table2.xlsx and table3.xlsx in Excel.
Go to Table1.xlsx. Select column A by clicking on A. Above that Column, you will see a box where cell number typically shows up. Click inside that and type in MyIDs.
Go to table2.xlsx. Create a new field called Matching IDs like so:
In Cell E2, type the formula:
=VLOOKUP(C2, table1.xlsx!MyIDs, 1, FALSE)
Hit enter. This formula means, take C2 (from table2) and find a matching row in table1.xlsx's named table called MyIDs (which is column A of table1). Then, choose the 1st column (which is the only column) from MyIDs. FALSE means do an exact match not an approximate match.
Click on E2. Copy it. Paste it into E3..En. You can drag to copy as well. That'll populate the formula in each cell in E column like this:
Click on sort and filter like this:
Click on Matching IDs dropdown and de-select #N/A
Highlight all rows and cells from the filtered data like so:
Copy. Go to table3.xlsx. Paste. Remove the extra column called Matching IDs at the end in table3.xlsx

Excel Formula: Count Matches Where 2 IDs have a Common Tag

I'm trying to figure out the most efficient way to do this in one cell's formula and would appreciate some assistance.
SHEET1
ID TAG
123 Flowers
123 Sports
135 Sports
456 Flowers
456 Cars
123 Clouds
456 Sports
SHEET2
ID1 ID2 RESULT
123 456 2 [WANT TO CALCULATE THIS]
135 246 0 [WANT TO CALCULATE THIS]
The way the formula should work is look in SHEET1 where both ID1 and ID2 have a tag in common and count them.
Here's one approach which should work for you.
Setup assumed:
Sheet1 data is in range A1:B8
Sheet2 data is in range A1:B3
Then formula that you should insert in Sheet2!C2 shall be:
=SUM((FREQUENCY(IFERROR(MATCH(IF(Sheet1!$A$1:$A$8=Sheet2!A2,Sheet1!$B$1:$B$8,"z"),IF(Sheet1!$A$1:$A$8=Sheet2!B2,Sheet1!$B$1:$B$8,"a"),0),"a"),IFERROR(MATCH(IF(Sheet1!$A$1:$A$8=Sheet2!A2,Sheet1!$B$1:$B$8,"z"),IF(Sheet1!$A$1:$A$8=Sheet2!B2,Sheet1!$B$1:$B$8,"a"),0),"b"))>0)+0)
NOTE: This is an array formula and shall be inserted by committing CTRL+SHIFT+ENTER and not just ENTER. If entered correctly, Excel put {} braces around it.

Transposing Data in Excel and Matching With a Unique ID

The first Excel file contains item analysis data for each student in the class:
Student ID Item # Response
101 1 A
101 2 B
101 3 D
101 4 B
Granted, this is just an excerpt of a file that has 500 unique student IDs.
In the second Excel file, I have the final grades for each student:
Student ID Grade
101 95
102 87
103 65
104 72
Again, this second Excel file has 500 unique student IDs. I need to make a file that essentially looks like the second Excel file, where each row represents a unique student ID and each column represents each test item and the final grade. How can I do this without resorting to copy and transpose paste?
On your final grade file, add columns for each item #. Assuming the first item # is in cell C2, and your item analysis data is in sheet Sheet1, put the following formula in cell C2 of your grade file, validate with Ctrl+Shift+Enter (it's an array formula), then copy across and down.
=INDEX(Sheet1!$C$1:$C$5000,MATCH($A2&"|"&C$1,Sheet1!$A$1:$A$5000&"|"&Sheet1!$B$1:$B$5000,0))
The answer is with 2 steps.
First you have to change the grade letters to numbers(for Excel t make an average on the 2nd step)
I took an example of grades but you can change it as you desire.
To switch the grades use the vlookup function. lets assume your first 3 coulmns are occupied with: Student ID Item # Response and your grade table is on columns e and F then on cell d2 insert the following :
=vlookup(a2,e:f,2,0)
Now you are ready to make an average of each student. the best way to to so is by a Pivot table. Choose all of the data and click on the insert ribbon to insert a pivot table. on rows get drag the students. and columns drag the fixed grade(numbers) the only thing left to to is to change the value from count to average.

If text in two cells exist, this creates a unique number

I am working with an excel file where I need a unique number created if the text in two cells are present: example
Text 1 Text 2 Value
star comet 100
star asteroid 101
asteroid nova 102
nova star 103
asteroid nova 102
star comet 100
nova star 103
I assume its something to do with the IF function but I'm now completely snowblind. Any help?
Thanks
Sort by column1 then by column 2
Use the Excel distinct function
Then add sequential ID to each row.
If you need to, use VLOOKUP to add the IDs to the original sheet
Without sorting, array formulae or VBA and assuming Text 1 is in A1, select ColumnsA:B, DATA > Sort & Filter - Advanced, Copy to: F1 (say), check Unique record only. In H2:
=F2&"|"&G2
in I2 enter 100 and copy H2:I2 down to suit.
In C2:
=VLOOKUP(A2&"|"&B2,H:I,2,0)
and copy down to suit.
A PivotTable is an alternative for constructing a list of unique pairs.

Resources