Unique values on multiple columns - excel

I need to get a list of unique values from few columns. The data looks like this:
I tried using Unique but it only gives me copy of the list. These 4 lists are already unique values found in another sheet.
If getting unique from 4 columns is impossible, how would I go around combining these 4 columns but instead merging data from a row to 1 cell I'd like to append that one column to have one city per row (so add more rows).
Another idea I had - pulling data from multiple sheets into 1 row, but as it's an automated report, number of towns in each sheet changes every time, so can't use specific cell locations.

You can use the following formula (entered into cell F2 and assuming your data is in range A1:D5)
=IFERROR(LOOKUP("zzzzz",INDEX(IF(COUNTIF(F$1:F1,A$2:D$5),0,A$2:D$5),MIN(IF(COUNTIF(F$1:F1,A$2:D$5),"",ROW(A$2:D$5)-ROW(A$2)+1)),0)),"")
As it is an array formula it needs to be entered using Ctrl+Shift+Enter and copied down until there are blank cells

It does not work in my case, in calc (LibreOffice) that i have exactly the same problem. To extract unique values from multiple columns with text, with blank spaces. I have tried a lot of formulas with no success...
What worked for me - I dont know why this worked for me!
A, B, and C contains text from the 2nd row and onwards. Formula is put on D2 cell as Array formula.
=IFERROR(IFERROR(IFERROR(
INDEX($A$2:$A$20; MATCH(0; COUNTIF($D$1:D1; $A$2:$A$20)+($A$2:$A$20=""); 0));
INDEX($B$2:$B$7; MATCH(0; COUNTIF($D$1:D1; $B$2:$B$7)+($B$2:$B$7=""); 0))
);
INDEX($C$2:$C$12; MATCH(0; COUNTIF($D$1:D1; $C$2:$C$12)+($C$2:$C$12=""); 0))
);
"")
Found here

Related

Sum column dynamically

Having A1+C1 and B1+D1 in two cells how can I dynamically set up a formula to catch if some column is added.
Let's say the user adds two columns in the middle. I should have A1+C1+E1 and B1+D1+F1.
I thought it would have been automatic but it is not.
Replace:
=A1+C1
By:
=SUM(A1:C1) - B1
In case you want to check if the column number is divisble by three, you can use following formula:
=IF(MOD(COLUMN(A1);3)=0;A1;0) // I've put the values from 1 to 10 in A1-J1
// and I've dragged this formula from A2 to J2,
// the values were 0,0,3,0,0,6,0,0,9,0.
Unfortunately I don't have a simple way to sum those values in one easy formula.
If you always add two columns then A1+C1 will always be looking at odd number columns and B1+D1 will always be looking at even numbered columns.
{=SUM(IF(ISODD(COLUMN($A$1:$D$1)),$A$1:$D$1))}
and
{=SUM(IF(ISEVEN(COLUMN($A$1:$D$1)),$A$1:$D$1))}
As long as you insert columns between A:D the ranges will extend to accommodate.
Edit:
Based on the comment that row 2 contains codes and row 3 contains the figures to add up for each code then this array formula will work:
{=SUM(IF($A$2:$J$2="H1",$A$3:$J$3))}
Edit2: and if I wake up you can even use the non-array and built in formula:
=SUMIF($A$2:$J$2,"H1",$A$3:$J$3)
The H1 text can be changed to another code or to a cell reference containing the code to get the sum of values in row 3 for the specified code.
As an array formula it must be entered using Ctrl+Shift+Enter.

How to compare each cell with each other in MS Excel?

In large dataset - 250 rows and 1000 columns I need to compare each value in cell with each other in one column and iterate over all column. Heres simplified example of source data:
And this is what I need (formatting not necessary and 2 empty rows not necessary) - if match if found "1" is produced, if no match "2" is produced, if one or both were N/A - "3" is produced:
Comparison should only be "one sided" for example Terry and Joey is the same as Joey and Terry, thus further comparison of already compared pairs is not needed.
Is it possible to do this in Excel 2016 or are there better tools for this?
My thanks to all.
This alternative is a bit complex, but we all solve problems like this differently. If it helps you, please feel free to use it. If not, I can understand since some of these techniques are not particularly common and the resulting formula is a bit unreadable. I did it this way so that I would be able to organize the rows better and read the matching/unmatching indicators more easily. I started by creating a helper column rather than repeat the rows for each individual so that each row shows the two names being compared. This is the formula I used to compare using B8's information is:
=IF(OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)<>INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE),2,1))
I am going to try to explain the formula I used as follows:
Without using the helper column, the basic formula for cell B8 is this:
=IF(OR(B$2="N/A",B3="N/A"),3,IF(B$2<>B3,2,1))
and this would work for the range B8:H11. However, when I skip down to B13, the formula would need to change to:
=IF(OR(B$3="N/A",B4="N/A"),3,IF(B$3<>B4,2,1))
and this would work for the range B13:H15. Likewise B17, and B20 would be:
=IF(OR(B$4="N/A",B5="N/A"),3,IF(B$4<>B5,2,1))
=IF(OR(B$5="N/A",B6="N/A"),3,IF(B$5<>B6,2,1))
for their respective ranges. I shy away from formulas where I have to remember what I need to change for each section (heaven forbid I should write any notes or read them if I did).
In order to do this, I used the person column (A) and my helper column (I) to determine which rows to compare.
MATCH($I8,$A$1:$A$6,0)
gives the row of the person value in the Chart from A1:H6 in the comparison
MATCH($A8,$A$1:$A$6,0)
gives the row of the helper value in the Chart from A1:H6 in the comparison
Since the data being compared is always in the same column, I just use COLUMN() to determine which column to use.
In cell B8, MATCH($I8,$A$1:$A$6,0) will tell me it is row 2 and MATCH($A8,$A$1:$A$6,0) will tell me it is row 3. Thus, I want to use the values in Row 2, Column 2 compared against Row 3, Column 2.
To tell Excel to compare Row 2, Column 2 against Row 3, Column 2 is fairly simple, but creating a formula that you can copy from cell to cell without having to modify it each time is not as easy, since each section is a bit different and there could be blank rows in between sections. What I did was to use indirect cell notation using "R1C1" syntax rather than the more common "A1" cell referencing.
In other words in column B8 this:
INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 2 (for Terry), Column 2 and
INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 3 (for Joey), Column 2 and
In both of the above, I am concatenating and R and a C to the numbers returned by the MATCH() and COLUMN() functions and using the FALSE parameter to tell Excel to treat the concatenated result as "R1C1" notation. In other words, this:
OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A")
translates to this:
OR(R2C2="N/A",R3C2="N/A")
I realize that the helper column is a burden you did not ask for and I realize that the formula is overly complicated, but I can freely copy this formula to any column that has the two names and it will do a comparison for that day of the week.
Here is a picture of what I am describing:
Added comments
Just to carry the above a bit further, suppose you had a Sheet1 which had the rows of data to be compared and suppose this were limited to 250 rows with the same 7 columns (rather than 1000). I could create another sheet similar to the above along with another helper cell (I put it in A1) to automatically populate the person column and the helper column like this:
New Helper Cell value: 1 (essentially saying to start at the top). This would populate Cell A2 with the following formula:
=IFERROR(IF(INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))=0,"",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))),"")
Basically this is just this formula:
=INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))
but is checking first to see if it results in zero and then is replacing it with blanks if it is an error. Copying this cell down Column A will populate that column with the names starting at the first row after the data row specified by A. If you have more headings or other data you would need to add additional amountst to the +ROW() portion in both occurrences in the formula. Column I gets populated siimilarly with this:
=IF(A2="","",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(LEFT($A$1,3)+1)))
However, this value does not vary from row to row.
Now that the helper columns are populated, you can populate the formula a bit differently from the above (which had used the same sheet) for example in B2:
=IF($A2="","",IF(OR(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)<>INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE),2,1)))
The main difference from the first formula is the off sheet references to "Sheet1" that were added and the extension of the formula to cover 250 rows.
Here is a picture with Cell A1 set to 1:
Here is a picture with Cell A1 set to 3:
Using this, your Sheet1 values remain where they are and you can create a generic comparison sheet to compare the values of various rows of Sheet1. These can be dynamically built by changing the value in A1 or you can create dozens of similar sheets, each differing by the value in A1.
Not sure if any of this makes sense.
Good Luck
Just use a function like this(exemple for cell B4):
=IF(B3=B2;1;IF(B3="N/A";3;2))
Print of it working
Do it for each line and just drag it from the begining to the end.
EDIT: You should do an or in the 2nd if to make surre neither is "N/A"
=IF(OR(B3="N/A";B2="N/A";3;IF(B3=B2);1;2))

Excel: An array in an array?

So, I would like to return the contents of all rows where the value in column A is, let's say, 1.
My thought process is that I could use:
=INDEX(row_range,MATCH(1,A:A,0),0))
But Match will only return one value here, i.e. the number of the first row which contains a 1 in column A.
Is there a way of creating an array with the Match formula (thus returning the multiple row numbers, all of which contain '1' in column A) and then place that in the Index array so that it then runs through each of the Match-array values and creates a big long list of values in one array which I can then list out on a separate sheet?
Hope this makes sense...
Here is a demonstration of what I'm hoping for, if that helps! The idea would be that the array as shown would be created, which could then be extended down the column as per the part underneath.
https://i.stack.imgur.com/nCusM.png
Use the file you showed in your example (as "Sheet1") and put these formulas into indicated cells in Sheet2:
Into cell A2 put
=AGGREGATE(15;6;ROW(Sheet1!A:A)/((Sheet1!A:A=1)*1);ROW(A1))
this will give you all the rownumbers where value in A column of sheet1 equals 1.
Into cell B2 put
=COUNTA(INDIRECT("Sheet1!"&A2&":"&A2))-1
this will give you how many cells are filled in that row.
Into cell C2 put
=TEXTJOIN(",";TRUE;OFFSET(Sheet1!$A$1;A2-1;1;1;B2))
This will give you all the cells with data from that row concatenated. If you dont have this formula (first time in 2016 I believe) you can use OFFSET function to list the values in separate columns and then CONCATENATE them.
Copy these three down as many times as you want and into cell C1 put
=TEXTJOIN(",";TRUE;OFFSET(C2;0;0;COUNTIF(Sheet1!A:A;1);1))

Excel - count multiple words per cell in a range of cells

I have some cells with multiple names in them as so:
Names are not repeated in the same cell.
I have some more cells below where I need to count how many times each name appears in each column. The names of the people counted above are to the right in one column, and the number of times each name appears should be calculated in the corresponding row of the next column.
For example, the cells that read 2 and 0 should read 4 and 4 (for the amount of times they appear in the previous image).
Here is an example of the desired result:
What formula should I use to accomplish this?
You can use an array formula (Ctrl+Shift+Enter) for this. Set up your list of names somwhere (For example, F1, F2, F3 ...) then next to it (in G1):
{=COUNT(IFERROR(FIND(F1,A:A,1),FALSE))}
Assuming A is you names column. Than simply drag G1 down to copy for all names.

Convert Semicolon Separated Values to Columns - Excel

I have a spread sheet of values organized by id number with a column of semicolon separated values.
I would like the spread sheet to be organized by id number with a column for each value and if that value exists for a id number a 1 be placed in the cell and if it doesn't exist a 0 placed in the cell.
Has anyone done this before or know where I should start?
You can try this but you need to keep the original value somewhere and then use this formula:
=IF(ISERROR(SEARCH(C$1,$B2)),0,1)
Your data layout should be like below:
So Column B contains your original data and your new headers starts at Column C.
Enter the formula in C2 and copy to the rest of the cells. HTH.

Resources