Taking Column A values comparing to Column B values if they are the same post to Column C - google-sheets

I'm trying to take the names from column A compare them to the names in column B and then have the similar names get listed in column C.
The problem is these names are automatically updated and out of order, and I need the function in column C to update with them. Also, the names will not be in order, this is why I can't use A=B function. The picture shown is an example of what the solution would look like or something similar. After completing this, I would like to continue using the same function to break down the name data even more. Watched a lot of videos on this, can't find anything specific enough to work.
Side note, I have found a way to do this using different pages within the sheets but not in the same sheet side by side. ex. of what solution
I have tried watching lots of YouTube videos, but nothing goes into detail enough and seem to only explain when similar values are next to each other in column A and B.
This is what I use for 2 different sheets but can't find / understand why when changing values in function to single sheet it wont work:
=filter(Sheet1!A2:B,ISNUMBER(match(Sheet1!A2:A,Raid1!A2:A,0)))
Also, another side note: Can't use True or False. And for uneven number of names in the list ex. Column A has 10 and B has 7 it sorts A for names in B and post similar in C.

Try below formula-
=FILTER(C3:C,INDEX(COUNTIFS(D3:D,C3:C))>0)

You can use VLOOKUP to check common values between columns and store them in another column.
=IFERROR(VLOOKUP(A:A,B:B,1,false),"")
Although this will create gaps in the output column. you can get rid of it by by simply using a filter or so.

all you need is:
=FILTER(C3:C; COUNTIFS(D3:D; C3:C))

Related

How do I return missing data when comparing two columns?

I've read a few similar questions, and I can't seem to find exactly what I'm trying to do.
I have a roster of employees in sheet "Roster" with their names in Column A. In sheet "Hours" I have a list of assigned jobs for tomorrow, with the assigned employee's name also in Column A. I'm trying to add a column of employees from the roster that are NOT in the list of employees on jobs.
The closest I've gotten is with this, on the Hours sheet:
=ARRAYFORMULA(VLOOKUP('Roster'!A2:A, A2:A,1,0))
which gives me a list of the entire roster, with the missing ones returning an #N/A error that tells me the missing name when I mouse over it and read the error code. Is there a way to just get a list of the errors? Would I be better off attacking this from a completely different angle?
EDIT: Sanitized example pictures. If what I was trying to do worked, it would return Bob and Jim in this example.
Assuming you're trying to return this list in the "Hours" sheet, you can build off what you had. Try this:
=ARRAYFORMULA(FILTER(A2:A,ISERROR(VLOOKUP('Roster'!A2:A, A2:A,1,0))))
Keep in mind that this formula was written sight-unseen. If it doesn't work as expected, consider sharing a link to a copy of your sheet (or to a sample sheet set up the same way and with enough sanitized but realistic data to illustrate the problem, along with the manually entered result you want in the range where you want it).
I ended up going a completely different route. I made a third "Under the Hood" sheet, pulled the two columns into it with queries, ran a match formula down the list and returned "" on errors, then ran a query on Hours to get the names where it had null for the match list.

Use Unique in a Filter formula

I have a list of identifiers and a value for each identifier which is filled automatically.
I want to filter the list so I will only get unique identifiers and their respective value.
e.g. "Dana" can appears 3 times but in the filtered table I only want to see the name (and the value) once.
Ideally I'd like to use something like
=filter(a:b,unique(a:a) which obviously doesn't work.
As mentioned, the list updates automatically so a formula that needs to be dragged won't do the trick.
Note: It can be solved by extracting uniques from col A
=unique(A:A)
and then an Arrayformula + vLookup
=arrayformula(if(I1:I>0,vlookup(I1:I,A:B,2,0),""))
but I'm curious to see if it can be solved using Filter for more elegance.
Here's an example (including the solution I mentioned):
https://docs.google.com/spreadsheets/d/1heKdV3U6mdGYkHCIWkeUyqo6AfhgV7ItSmolibH7ecU/edit?usp=sharing
Please use the following
=UNIQUE(A:B)
UPDATE
Following OP's comment/request:
Nice fix! Out of curiosity - is it possible to still use it with the filter function (for example, if I wanted to filter by Col B or add other restrictions) ?
Sure. Try these ones out
=UNIQUE(FILTER(A:B,B:B=333))
OR
=FILTER(UNIQUE(A:B),UNIQUE(B:B)=333)
Reference:
UNIQUE

ARRAYFORMULA with IMPORTRANGE

In column B are listed IDs of Google Sheets. In column C are listed cells, from which I want to import data.
Screenshot of the table
In column D is shown the result of using IMPORTRANGE() by simply dragging it. e.g. for D1 it looks like:
=IMPORTRANGE(B1;C1)
for D2:
=IMPORTRANGE(B2;C2)
and so on.
In column E I want to display the same result but using ARRAYFORMULA that looks like:
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4))
but the function displays only the data from the first spreadsheet.
People complain about this permissions issue a lot, but it's not hard to solve. What I do is have a sheet which I name "Splash sheet" into which I paste the URLs of the documents I wish to link. To its right is a column headed "permit to connect" which contains IMPORTRANGE formulas importing a single cell from each sheet -- usually a cell containing a confirmation code, number or document name -- on a sheet also named "Splash Sheet." For example,
=IF(B3="enter URL",,CONCATENATE(IMPORTRANGE(B3,"Splash sheet!A1")," ",IMPORTRANGE(B3,"Splash sheet!B1")))
So, when you first connect a spreadsheet via its URL, you get those messages telling you you need to connect, you click the Permit Access, the confirmation code/number/document name appears in the second column, and voilá, your sheets are connected forevermore! Now all your other IMPORTRANGEs referencing that URL will work, and you can use IMPORTRANGE formulas that reference the URL-containing cells on the "splash sheet."
As for the OP's original question, I came here seeking an answer to the same problem, and after more research have realized that we are attempting the impossible here. No way to do this an ARRAYFORMULA. No way around writing formulas that reference every single cell a document's URL may go into.
Problem is you can't make arrays of arrays in spreadsheets; that would involve multiple dimensions, and the medium is inherently two-dimensional. This is what people use databases for.
ARRAYFORMULA doesn't work when importing data (I think it relates to permissions). You could use something like this, =IFERROR(IMPORTRANGE(B5:B7;C5:C7)) and pre-fill the column first, but still there would be the permissions issue. Each new imported sheet needs it's permissions granted by a user.
TLDR: If I understand your intention correctly when you say you would like to see
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4)), I believe you can make that
happen using the following.
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
Breakdown
Use IMPORTRANGE with INDIRECT to create ranges inside ARRAYFORMULA
Call INDIRECT with the ADDRESS function
Call ADDRESS with the ROW and COLUMN functions since they take ranges via ARRAYFORMULA
using IMPORTRANGE with INDIRECT
IMPORTRANGE's two parameters are the spreadsheet url stored in B2:B4 for this example and the range (e.g. sheet!A1:B2) stored in C2:C4.
Since IMPORTRANGE doesn't take a range reference directly as you mentioned, you'll need to build it for each row with ARRAYFORMULA using the INDIRECT function.
INDIRECT can be used to compose a cell reference using A1 notation, for instance
=IMPORTRANGE(INDIRECT("B" & 2), INDIRECT("C" & 2))
will produce the same result as
=IMPORTRANGE(B2, C2)
Since this produces the same result, we now just have to find a way to make INDIRECT work with ARRAYFORMULA
Use ADDRESS to build the parameters for INDIRECT
Next you want to use ADDRESS to build the A1 reference for INDIRECT. For the current purposes, ADDRESS takes a numerical value for row and column as parameters
=INDIRECT(ADDRESS(2,2))
will produce the same result as
=INDIRECT("B" & 2)
Since these two are interchangeable, now we just need to find a way to get the numerical row and column values out of ARRAYFORMULA.
Call ADDRESS using the ROW and COLUMN functions
From there, you can get the row and column indexes from standard A1 notation using the ROW and COLUMN functions. While this may seem like we're pointlessly going in circles, the difference now is that ROW and COLUMN perform as expected with the ranges provided by ARRAYFORMULA. So given that ADDRESS will return $B$2 using using either method below
=ADDRESS(2,2)
or
=ADDRESS(ROW(B2),COLUMN(B2))
we now know that
=ARRAYFORMULA(ADDRESS(ROW(B2:B4),COLUMN(B2:B4)))
will produce the following array of addresses
{ $B$2; $B$3; $B$4 }
Final Assembly
So when we put this all together, we get
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
where INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)) is more or less interchangeable with what you might expect from B2:B4 inside ARRAYFORMULA and represents the url parameter
and INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4)) is roughly interchangeable with what you might expect from C2:C4 inside ARRAYFORMULA and represents the range parameter.
Suggestions on organization
I recommend using the indentation (Alt +Enter to create a new line ) above along with your indentation of choice to keep it easier to read. In the end it's just a bit more syntactic sugar and if spaces are used well it shouldn't be much harder to understand and make changes to 6 months later.
RE: Permissions - as mentioned by Atiq Zabinski, just placing a simple
IMPORTRANGE("http:/xxxx", "A1") somewhere on the sheet will provide a
means to know if the sheet is connected or not and the error message
should give you a context menu for connecting the sheet. You'll might
want to stay away from error handling in these scenarios as it will
slow down the process of connecting the sheets.

google sheets - Arrayformula

I have created a form using google forms, and I want to automatically check the answers when a new submit is done.
When the user submit his/her question, a new line is added in a responses sheet. This is where I need to add some magic ;)
SO, in my responses sheet, I have the right answers in the second line...something like this
A B C
1
2 RightAnswer1, RightAnswer2, RightAnswer3....
Using the arrayformula function, I have added new colums (column D,E,F,G and so on) on every row checking against the correct answer on line 2.
The formula goes something like this;
=IF(ARRAYFORMULA(A3:A=A2),1,0)
And it works like a charm :)
BUT, then I want to add a column at the end of each row with the sum of all the right answers, lets say to column Z on every row...this is where I want to sum all the 1's (correct answers).
I have tried something like this;
=IF(ARRAYFORMULA(<any kind of check that is true>),sum(D3:Z3),0)
This will always return the sum of D3:Z3 on every line, and this is not what I want. I want to sum the columns on the line-number that was just added. So I have tried to alter this expression in several ways , having everything in the arrayformula expression, altering the sum expression to (D3:D) to hopefully get it to work on the current line, but without any luck.
I have search the web for answers, but found nothing to help me...
Do you have any suggestions?
One way:
=ArrayFormula(IF(LEN(D3:D),SUMIF(IF(COLUMN(D3:Z3),ROW(D3:D)),ROW(D3:D),D3:Z),))
Although it would be possible to "skip the middle man" and process the raw data alone; assuming the answers are in A2:Z2, and the data to sum is in A3:Z, then:
=ArrayFormula(IF(LEN(A3:A),COUNTIF(IF(A3:Z=A2:Z2,ROW(A3:A)),ROW(A3:A)),))

Stacking multiple columns on to one?

I am using Google SpreadSheet, and I'm trying to have multiple sheets containg a list of words. On the final sheet, I would like to create a summative list, which is a combination of all the values in the column. I got it sort working using =CONCATENATE() , but it turned it into a string. Any way to keep it as a column list?
Here is an example as columns:
Sheet1
apple
orange
banana
Sheet2
pineapple
strawberry
peach
FinalSheet
apple
orange
banana
pineapple
strawberry
peach
Updated Answer
I was right there is a much better solution. It's been posted below but I'm copying it here so it's in the top answer:
=unique({A:A;B:B})
Caveat: This will include one blank cell in certain scenarios (such as if there's one at the end of the first list).
If you're not concerned with ordering and a tailing blank cell a simple sort() will clean things up:
=sort(unique({A:A;B:B}))
Otherwise a filter() can remove the blanks like so:
=filter(unique({A:A;B:B}),NOT(ISBLANK(unique({A:A;B:B}))))
The following is the old deprecated answer
I'm confident that this is "The Wrong Way To Do It", as this seems such an absurdly simple and common task that I feel I must be missing something as it should not require such an overwrought solution.
But this works:
=UNIQUE(TRANSPOSE(SPLIT(JOIN(";",A:A,B:B),";")))
If your data contains any ';' characters you'll naturally need to change the delimiter.
The basic way, is just to do it as arrays like so
={A1:A10;B1:B10...etc}
The problem with this method, as I found out is that its very time consuming if you have lots of columns.
I've done some searching around and have come across this article:
Joining Multiple Columns Into One Sorted Column in Google Spreadsheets
The core formula is
=transpose(split(arrayformula(concatenate(if(len(A:Z)>0,A:Z&";",""))),";"))
Obviously you'd replace the A:Z to whatever range you want to use.
And if you want to do some sorting or removing duplicates, you'd simply wrap the the above formula in a SORT() and/or UNIQUE() method, like so..
=sort(unique(transpose(split(arrayformula(concatenate(if(len(A:Z)>0,A:Z&";",""))),";"))))
Hope this helps.
Happy coding everyone :)
You can use this:
=unique({A1:A;B1:B})
Works perfect here!
The unique() function gets rid of blank spaces, but wasn't helpful for me because some of my rows repeat. Instead I first filter the columns by len() to remove blank cells. Then I combine the columns together in the same way.
={filter(A:A, len(A:A)); filter(B:B, len(B:B))}
Much more simple:
={sheetone!A2:A;sheettwo!A2:A}
Use flatten, e.g. flatten(A1:B2). More details in this article.
If the 2d range is not in one piece, one can be created first with the ampersand or similar techniques. Afterwards flatten can be called on the resulting 2d range. The below example is a bit overkill but it is nice when working with dynamic 2d ranges, where the basic solution can't be easily used.
flatten(ARRAYFORMULA(SPLIT(ARRAYFORMULA(A1:A2&";"&C3:C4), ";")))
The article shows also how to easily unflatten a range using the, as well undocumented, skipping clause in a query.
=TRANSPOSE(SPLIT(TEXTJOIN("#",TRUE,TRANSPOSE(A:C),TRANSPOSE(D1:D5)),"#",FALSE,FALSE))
use a preferred delimiter absent in the data (instead of #) if needed
the first 1 (TRUE) parameter means IGNORE EMPTY, which is very important in this case..
the A:C and D1:D5 are the ranges to combine
all values remain there - not using UNIQUE
Try using your CONCATENATE argument with
=ArrayFormula(EXPAND(...))

Resources