Excel: Transpose data from rows to column headings - excel

My problem, as the title states, has to do with transposing data from rows to columns
The original data came into a csv format where in the second column 'Dates and Rank' semicolons and spaces acted as delimiters.
Country Dates and Rank
Switzerland [2014-03-07] 7;[2014-10-17] 7;
USA [2011-07-01] 7;[2012-02-17] 7;[2012-09-30] 7;[2013-01-31] 7;
France [2011-07-01] 4;[2012-02-17] 4;[2012-09-30] 4;
China [2015-01-16] 7;[2015-03-06] 7;[2015-10-16] 7;[2015-10-23] 7;
So, by using the Text to Columns function from excel I separated the data within 'Dates and Rank' column into different cells. And now the result looks like this:
Country Dates and Rank C D E F G H I
Switzerland [2014-03-07] 7 [2014-10-17] 7
USA [2011-07-01] 7 [2012-02-17] 7 [2012-09-30] 7 [2013-01-31] 7
France [2011-07-01] 4 [2012-02-17] 4 [2012-09-30] 4
China [2015-01-16] 7 [2015-03-06] 7 [2015-10-16] 7 [2015-10-23] 7
*I have also deleted the square brackets from the dates and I assigned them as YMD cells.
But what I need to do now is to use the dates as headings while I use the rank (1-7) as their allocated data within the cells. For example:
Country 2011-07-01 2012-02-17 2014-03-07 2014-10-17
Switzerland 6 7
USA 5 7
Any suggestions please?
Thank you.

I'll assume your data starts in cell A1 (i.e. A1 contains "Country").
First, create a new worksheet where your newly ordered data will come. You first need to fill in the column header row. You can do this by
manually copy-pasting all the date columns from your original data to a single column in the new worksheet, so that all dates are in one column
Remove duplicates (in the ribbon: Data > Data Tools > Remove Duplicates)
Sort the list if you want (Data > Sort & Filter > Sort)
Select the resulting data, copy, and transpose-paste in cell B1 (Home > Paste > Paste Special, and check the box "transpose"). Now you can also remove the data you just copied.
Second, copy-paste column A of the source worksheet into column A of the destination worksheet.
Finally, for each country and each date you want to look up the data right next to the date. You can do this by using the following formula in B2:
= IFERROR( INDEX( Sheet1!2:2, 1, MATCH( B$1, Sheet1!2:2, 0 ) + 1 ), "" )
Finally, copy this formula down and across.
This should do the trick just fine, but it is not a very flexible solution and you need to follow the steps exactly as explained. For example, if the countries are in a different order than they are in your original data sheet, it won't work.

Related

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),))

Adding new rows to make an Excel spreadsheet complete

Let's say I have an Excel sheet like the below:
states incidents years
1 Texas 1 2000
2 Texas 1 2008
3 Arizona 2 2004
4 California 1 2002
5 California 4 2007
I want to create new rows with the value of 0 for states which had no incidents. For example, I'll create seven new rows for Texas, indicating that it had zero incidents from 2001 to 2007. Arizona will have eight new rows (for all years from 2000 to 2008, except 2004).
How can I do this in Excel? Obviously I can do it manually but I'm wondering if there's a way to automate the process.
Make a new table on Sheet2 that fills up with either data from the first table or with zeros.
For the 2-D version: Put the state in the top row and the year on the left row. Fill the data with an equation like this (starting in cell B2):
=iferror(index(Sheet1!$C$2:$C$6, match(B$1 & "_" & $A2, Sheet1!$B$2:$B$6 & "_" & Sheet1!$D$2:$D$6, 0)), 0)
When you type the formula, accept it by hitting ctrl+shift+enter. This is an array function.
For the 1-D version, put the state in column A and the year in column B. Now make column C:
=iferror(index(Sheet1!$C$2:$C$6, match($A$ & "_" & $B2, Sheet1!$B$2:$B$6 & "_" & Sheet1!$D$2:$D$6, 0)), 0)
(Don't forget to hit ctrl+shift+enter)
If you format the original data as a Table by using Insert > Table, you will see that the formulas you type get replaced with clever column titles... this will make the entire table's data available to the formula, no matter how much data gets added. Very useful.

Excel, How to write a formula that fits these criteria

A B C D E F G
1 Date: 9/15/2016 9/16/2016 9/17/2016 9/18/2016 9/19/2016 9/20/2016
2 Points: 0.5 1 - - 0.5 1
The above data is on tab 1 of an excel spread sheet
And below are fields on tab 2 of the same excel spread sheet:
A B
1 DATE: Points
2
3
4
5
I am trying to write a formula that will go through the dates and points rows on tab 1 and when it finds a date with a corresponding point it will populate that date in tab 2 under the Date column. Simple enough right? Well here's where I'm running into problems, I need a formula to include the following criteria:
1) If the date does not have a corresponding point in the second row on tab 1 it will skip it and move on to the next date to validate it and so on
*note- I also need the Points column on tab 2 to populate with the corresponding date, but I believe a simple HLOOKUP formula will work just fine
2) I would like to have the formula to where it can be duplicated on tab 2 cells A3,A4,A5 and so on, but as an example: if A2 has date of 9/15/2016, when the formula in A3 is checking for dates with corresponding points in tab 1, it will skip the date in tab 2 located in A2 since it's already been used
Below is a picture of the above data in case it didn't come out right, and thanks for the help!!
Use this array formula:
=IFERROR(INDEX('Tab1'!$B$1:$G$1,MATCH(1,('Tab1'!$B$2:$G$2<>"")*(COUNTIF($A$1:A1,'Tab1'!$B$1:$G$1)=0),0)),"")
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done correctly then Excel will put {} around the formula.
This will create a list as it is dragged/copied done. The list will be in the same order as the list on tab1.

Consolidate two or more columns of data into one column using formula

I need to collect Sch Code from different columns into one column as shown below.
First priority is by formula or UDF Function if possible.
My Data:
Column A Column B Column C Column D Column E Column F Column G
SCH Code Value SCH Code Value Rating SCH Code Value
C01-3-1 4 C01-4-1 8 300 C02-3-1 8
300 C02-3-5 9
C01-3-2 5 C01-4-2 12 300 C02-3-2 12
C01-3-3 6 C01-4-3 21 300 C02-3-3 21
300 C02-3-6 10
C01-3-4 7 C01-4-4 4 300 C02-3-4 4
Required Result (Only Sch Code required in summary sheet but it is required by formula or VBA UDF function) :
Column A
C01-3-1
C01-3-2
C01-3-3
C01-3-4
C01-4-1
C01-4-2
C01-4-3
C01-4-4
C02-3-1
C02-3-5
C02-3-2
C02-3-3
C02-3-6
C02-3-4
You can collect unique non-blank values from column A with an array formula e.g. =INDEX($A$2:$A$99,MATCH(0, IF(LEN($A$2:$A$99),COUNTIF(I$1:I1,$A$2:$A$99),1),0)). Since this returns #N/A where it has no more values to return from its column, you can pass control over to a similar formula that references another column with IFERROR.
    
To choose from your three columns of SCH Codes, you would need to stack this 3 deep. The formula in I2 is:
=IF(LEN(I1),IFERROR(INDEX($A$2:$A$99,MATCH(0, IF(LEN($A$2:$A$99),COUNTIF(I$1:I1,$A$2:$A$99),1),0)),IFERROR(INDEX($C$2:$C$99,MATCH(0, IF(LEN($C$2:$C$99),COUNTIF(I$1:I1,$C$2:$C$99),1),0)),IFERROR(INDEX($F$2:$F$99,MATCH(0, IF(LEN($F$2:$F$99),COUNTIF(I$1:I1,$F$2:$F$99),1),0)),""))),"")
This array formula requires Ctrl+Shift+Enter, not just Enter. Once entered correctly, it can be filled down to catch all possible values. I would fill down for at least three times as many rows as you have in order that the blanks would have a place if they were filled in at a later date.
In theory, you could stack this much deeper but for practical purposes, I wouldn't go much deeper than this. Array formulas eat up calculation resources at a logarithmic rate so the size of your data is going to be a key factor on whether this is a suitable solution.
One solution:
Copy and paste all values in column C below column A data. Highlight column A and go to Data>Remove duplicates then Data>Sort.

Format Cells from 2 sheets, based on 4 column comparison

I need to find changed values in dataSet.
So I have 2 sheets with, in general, same data.
I have two columns: docID(which is unique key) and rev(which is not unique).
I need to find(highlight/display only/...) those rows, where for same docID from first sheet rev is different in the second sheet.
UPDATE 1
Sheet 1:
docID rev
1 5
2 6
3 1
Sheet 2:
docID rev
1 6
2 6
3 1
Only the first row makes an interest to me, as others did not changed.
UPDATE 2
simple if statement which should give some understanding what I need. In general this is done on similar test data set, so cells are incorrect.
=IF(NOT(AND($B6=Sheet1!$B6;$C6=Sheet1!$C6));1;0)
So values are NOT equal.
You can do this with a custom formula in Conditional Highlighting:
Select the top cell in the column docID column, then select the whole column (in the example, I assume that this is column A and you select A1 and the rev is in column B, same structure in both sheets. Adjust as to your needs)
Goto home->Conditional Formatting->New rules->Use formula to determine which cells to format and enter the following formula:
=VLOKUP(A1,Sheet1!$A:$B,2,0)<>B1
Click on format and select the format you need.
Done!

Resources