Why can't I use multiple LIKE NOT in google query? - google-sheets

I am currently trying to narrow down my data. I want to eliminate certain values that I do not want to pull in the query.
First I want to eliminate the - (dash)
=query(A1:B,"select A where NOT A LIKE '%-%'")
That works,
But, if I want to continue to narrow down my data I use
=query(A1:B,"select A where NOT A LIKE '%-%' or NOT A LIKE '%WOLF%'")
That does not work. Instead of narrowing down my data it adds the dash back and keeps wolf . How can I keep using NOT like for multiple strings?

Use parentheses to make the logic easier to follow, like this:
=query(A1:A, "where not (A like '%-%' or A like '%WOLF%')", 0)

better to use regex like:
=QUERY(A1:A, "where not A matches '.*-.*|.*WOLF.*'")

Just to add to this conversation, the second query will return anything that does not have Wolf AND a dash in it. So if I have "Wolf-man" and "Gray Wolf" in my data. I will get "Gray Wolf" back but not "Wolf-Man." Why?
The OR operator tells the query to return something if it's not like one OR the other. "Gray Wolf" is not like '%-%'. Even though it would get filtered by the OR '%Wolf%' language, it's captured by the first part of the OR statement, and so the query says "Yes, this is like this or that, since it is like your no-dash language, I'll return it." And visa versa. If you had "Mole-person" in your data, that would pop up, since it's not like '%Wolf%' and the query will say "well, i's got a dash but it's not a wolf, so I'll include it."
Users above suggested the AND operator, since that is what you'll need in order to filter out BOTH wolves AND dashes. The way it is written, a cell must be like BOTH for the query to exclude it.
I hope this clarifies.

Related

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

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

Google Sheets Query Match/Return data

Need to return data based on matching two columns from different sheets. Help appreciated
={"Video Views";ARRAYFORMULA(INDEX('Sheet1'!K2:K, MATCH('Sheet1'!Z2:Z,'Sheet2'!E2:E,0)))}
These are two exports that need matched by link, and return column k "video views" Exports
It is always tough to write formulas without context. But it sounds like you are trying to use this in Sheet2, in the top cell of some column that is parallel to Column E in that sheet. If that is true, you can use this:
=ArrayFormula({"Video Views";IF(E2:E="",,IFERROR(VLOOKUP(E2:E,{Sheet1!Z2:Z,Sheet1!K2:K},2,FALSE)))})
It looks like you are trying to use arrayformula+index+match to get an array of the lookup values, and then using {} to append that to "Video Views", which I'm guessing is your column header, so you can get all the answers in one calculation. Don't. Just use index/match by itself, then copy it down. It will be easier to troubleshoot, easier to maintain, easier to read, and probably perform much better.
I'm going to guess that you want to get the video views into Sheet1!L:L (the bottom half of your image), and you want to use the values from Sheet1!F:F to match against the links in column Z on Sheet2, and return the video views from Sheet2!K:K.
If that is the case, the try this formula in Sheet1!L2:
=INDEX(Sheet2!K:K, MATCH(Sheet1!F2, Sheet2!Z:Z, 0))
and then copy that down.
But I am really just guessing.

Removing observations from SPSS Dataset

I would like to delete some observations from the table in my SPSS, if values meet, for instance:
If product + value from column meet, I want to remove it/make it SYSMIS (only this observation, the observation from another column for this row needs to be still available, so make flag and temporary select is not enough)
Tried several approaches like:
RECODE VAR2(If(PRODUCT=1 AND VAR2=2000) = SYSMIS)(ELSE=COPY)
EXECUTE.
IF(PRODUCT=1 AND VAR2=2000) RECODE VAR2(SYSMIS)(ELSE=COPY)
EXECUTE.
None of it works
Is there a way to remove observations in another way than delete it from raw data? I'd like to avoid it
You might save a lot of work by looking up some basic spss syntax tutorials. See here for a good site.
In the present case all you need is this:
If PRODUCT=1 AND VAR2=2000 VAR2=$SYSMIS.
To make your syntax work with recode, you can do this:
DO IF (PRODUCT=1 AND VAR2=2000).
RECODE VAR2 (ELSE=SYSMIS).
END IF.
It sounds like you might not want to delete the original data, but instead just run your analyses on a subset of data. In that case, use SELECT IF:
SELECT IF (PRODUCT=1 AND VAR2=2000).
Or:
SELECT IF NOT (PRODUCT=1 AND VAR2=2000).
This will delete any row that doesn't fit the condition, and so all subsequent analysis will include only the rows that do.
If you want to be able to filter the rows only temporarily - you can use filter command instead of select.

google spreadsheets FILTER multiple ranges/columns (A13:B and E13:G)

I was wondering if it's possible to use multiple ranges/columns when using FILTER
Right now I'm simply using the formula multiple times, like so:
=filter((Sheet1!A13:B),Sheet1!N13:N>E2,not(iferror(search("AS -", Sheet1!O13:O))))
=filter((Sheet1!E13:G),Sheet1!N13:N>E2,not(iferror(search("AS -", Sheet1!O13:O))))
I'm wondering if something like this would be possible (example below doesn't work)?
=filter((Sheet1!A13:B,Sheet1!E13:G),Sheet1!N13:N>E2,not(iferror(search("AS -", Sheet1!O13:O))))
I know using QUERY is easier in this case, but I'd like to know if I can do the same with FILTER (since I haven't been able to figure it out)
Yes, this can be done using array notation (curly braces), for example
=filter({Sheet1!A13:B,Sheet1!E13:G}, Sheet1!N13:N>E2)
The notation {range1, range2, range3} means putting these ranges side by side (they must have the same number of rows). Similarly, {range1; range2; range3} means stacking them vertically (they must have the same number of columns).

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