Transposing Data in Excel and Matching With a Unique ID - excel

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.

Related

Conditional Formatting in Pivot Table in Excel based on text field

I would like to color code a pivot table based on a text field within the data.
This is a mock up, as I'm at a loss as to how this can be done. One of the tricky parts is that you can't actually display the text field that is the basis for the color.
Thank you,
Neil
Contract
Month
PayStatus
Payment
1
Jan-21
Complete
90
2
Jan-21
Complete
95
3
Jan-21
Complete
93
4
Jan-21
Complete
94
1
Feb-21
Pending
91
2
Feb-21
Complete
95
3
Feb-21
Complete
92
4
Feb-21
Complete
94
2
Mar-21
Complete
96
3
Mar-21
Pending
93
4
Mar-21
Pending
94
2
Apr-21
Complete
95
3
Apr-21
Pending
94
Mock-up Pivot Mock-up (color coded)
You still don't need to use VBA to get the results you're looking for, but there is a little work to do in order to set it up. The solution is to use Conditional Formatting in which the formula is VLOOKUP. To make it work, you need to modify your table slightly.
VLOOKUP works by finding a unique value in the first column of a table or range. The first column values in your table are not unique, nor are the values in the second column. But if you combine the first and second columns, you can create a unique value. A column must be added to the left of your data to create this unique value:
The formula in Column A combines the values in columns B and C:
=B2&"+"&TEXT(C2,"mmm")
(There's a reason to format the date as just the Month, more later)
What we're ultimately looking for in your formatting rules is when any value in the pivot table, for a given month and contract, matches either "Complete" or "Pending". Because we've set up the data with the helper column, we can now create a `VLOOKUP' that can work for us. So we need a formula that does this:
VLOOKUP(unique value based on month and contract,get the pay status) = "Complete"
VLOOKUP(unique value based on month and contract,get the pay status) = "Pending"
The formula in the VLOOKUP has to reference back to the source data (when it's inside the pivot table). In order to lookup that unique value, we have to create it by combining values from the pivot table. If the VLOOKUP formula was in Cell B6 in the pivot table:
Then the formula will be:
=VLOOKUP($A6&"+"&B$4,Sheet1!$A$1:$E$14,4,FALSE)="Complete"
Notice how the "lookup value" is not a single cell, but we're creating the same unique string/value in the helper column.
In your pivot table, click in the values area ("Sum of Payment") in Cell B6, then select Home -->Conditional Formatting-->Manage Rules. Next "Add New Rule" and then make sure your rule looks like this:
Create a second rule in the same manner and apply it to the pivot table.

Removing specific rows in Excel

I have a data set in Excel as shown in the snippet below:
Patient Number Age State
1 20 1
1 20 3
1 20 2
2 35 1
2 35 4
3 62 2
3 62 1
3 62 3
3 62 4
3 62 5
I need to keep the last row of each patient, i.e. I need the dataset to look as follows:
Patient Number Age State
1 20 2
2 35 4
3 62 5
Is there a simple way to do this with Excel? Since the dataset is huge and cannot do it manually
If your data is in A:C columns, you can add another column with the following formula in D2:
=A2<>A3
Fill it down. Apply autofilter, choose False in D column and delete all filtered rows.
Edit:
This solution assumes your data is sorted by A column.
Enter below to D2 and press CTRL+SHIFT+ENTER to make it an array formula:
=MAX(IF($A$2:$A$11=A2,ROW($A$2:$A$11)))=ROW()
Advantage of this formula is PatientNumber column doesn't have to be sorted. Formula will find the last entry for each PatientNumber. See below, added one more row for Patient number 1:
You can easily keep the top entry with Data ► Data Tools ► Remove Duplicates. To keep the last entry, you first need to reverse the order.
In an unused Helper column to the right put a 1 in the top row then select all of cells in that column to the bottom of your data and use Home ► Editing ► Fill ► Series to gain a column of sequential numbers.
Sort your data using that new column in descending order.
Choose Data ► Data Tools ► Remove Duplicates using only the Patient column as the criteria for duplication.
Delete the Helper column as it is not longer needed.
Duplicates are deleted from the bottom up so the first value for each patient will be retained.

Automatically working out the average of filtered results

I have a spreadsheet where column P has a score between 1-6
The cell O4 has the following formula: =AVERAGEIFS(P8:P5000,P8:P5000,"<>6",P8:P5000,"<>0")
This formula searches for the average of the score in column P excluding 6, blanks and 0
Column O has staff names e.g John, Mark, Tim.......
What i want to do is for Cell O4 to automatically calculate the average of the figures shown in column P after i have used the filter function to show only results of a selected staff member.
I was hoping excel might be able to do this automatically however cell O4 appears to still be showing the average of the whole column P regardless of whether i have filtered or not.
I was given the formula below on another forum but it seems to be giving slightly wrong results albeit only by a small amount but i need to have the results exact if possible. Any help appreciated.
=SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(9,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))/SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(2,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))
Maybe
{=AVERAGE(IF((P8:P5000<>6)*(P8:P5000<>0)*SUBTOTAL(103,INDIRECT("O"&ROW(8:5000))),P8:P5000))}
will do what you want. Assuming the Filter is on column O.
The 103 in SUBTOTAL will also exclude if rows are manually hidden. If this ist unwanted and it should only exclude hidden rows, if filtered, then use 3 instead.
This is an array formula. Input it into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter] to create the array formula.
I would create a separate table in a new sheet with all unique staff members and then perform the calculation. This way, you can quickly compare values for all staff just by scanning the table instead of having to constantly update the filter to see the values for potentially dozens or hundreds of staff. You would add the staff name range and criteria to your AVERAGEIFS formula.
For your example:
Sheet 2
A B
--- ---
1 | Staff Average
2 | Bob =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A2,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
3 | Mary =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A3,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
4 | Joe =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A4,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")

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.

Generating letter by its position in the alphabet

I want a formula that can return the letter of the excel alphabet (27 = AA etc.) of a given number.
The purpose of this is that I have a table that returns values in a spreadsheet. I am summarizing data of climate measurements in cities, this data takes up 4 columns (but the same rows and relative positions in each column, so I29 and J29 contain 2 numbers I need, and then M29 and N29 contain the same data for the next location.
I want to create a summary table that looks like the below
City Rainfall Average Sunshine Average
City A =I29 =J29
City B =M29 =N29
City C etc.
my problem is that i go up to a few hundred cities, and i want to be able to populate the cells automatically/fill down. I know what row the data is in but need to generate the column letters using the formula requested above, so I can use a concatenate to create the cell reference.
You can use the ADDRESS function.
For example, =ADDRESS(29,27) will return the string "$AA$29".
However, honestly in your situation I would use the OFFSET function, combined with ROW(). To illustrate, let's say your table starts with a header row on row 50 and data starts on row 51. The data for a given city would start (ROW() - 51) * 4 columns to the right of I29. So:
A B C
50 City Rainfall Average Sunshine Average
51 City A =OFFSET($I$29,0,(ROW()-51)*4) =OFFSET($I$29,0,(ROW()-51)*4+1)
52 City B =OFFSET($I$29,0,(ROW()-51)*4) =OFFSET($I$29,0,(ROW()-51)*4+1)
53 City C etc.
Of course, you have to be careful if you want to move these cells around; you'll have to change the 51.

Resources