Unique filter condition - google-sheets

I have a rather complex goal in mind, but in short, I'm trying to make a filter on a range that would only leave unique names which have a condition "Add" and not "Remove". Problem is, the data will be continuously populated via form submission and some names will be removed and re-added down the road, so if same name is encountered in the range and has both one "Add" and one "Remove"(or equal amount of add and remove) - it shouldn't show up in filtered data. Please see the spreadsheet below for example.
https://docs.google.com/spreadsheets/d/18n7b6hEh9X3A14-PCQSwOPQr8nTin2X9-NBKmPSv48Q/edit#gid=0
Alternatively i was thinking of collecting the latest encounter of the unique name. So if the same name is encountered multiple times - retrieve the entry which is closest to today and only show it if condition matches "Add". This solution would be more beneficial but seem to be harder to achieve.
Either solution would help a lot. Appreciate your insight.

may be use double query:
=QUERY(QUERY(A2:C11,"select C, count(A) where B <> '' group by C pivot B"),"select Col1 where Col3 is null")
also this formula could work:
=UNIQUE(FILTER(C2:C10,ArrayFormula(MMULT(--(C2:C10=TRANSPOSE(C2:C10)),--(B2:B10="Remove")))=0))

You can try this.
=unique(query(arrayformula(iferror(if(isodd(COUNTIF(C2:C8,C2:C8)),C2:C8,""))), "select Col1 where Col1 is not null order by Col1 desc", 0 ))

Related

How can I separate a column into multiple columns based on values?

I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.
I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this
I'm okay with the start of the formula
=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")
But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.
Do you have a solution for what I'm trying to do? Thank you in advance :)
Solution:
It's not possible in Google Query Language to have a single query statement that has one result grouped by one column and another result grouped by another.
The first two columns can be like this:
=QUERY(A2:C,"select month(A)+1, sum(B) where A is not null group by month(A)+1 label month(A)+1 'Month', sum(B) 'Amount'")
To create the column labels for the succeeding columns, use in the first row, in my example, I1:
=TRANSPOSE(UNIQUE(C2:C))
Then from cell I2, enter this:
=COUNTIFS(arrayformula(month($A$2:$A)),$G2,$C$2:$C,I$1)
Then drag horizontally and vertically to apply to the entire table.
Results:
try:
=INDEX({
QUERY({MONTH(A2:A), B2:C},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"),
QUERY({MONTH(A2:A), B2:C, C2:C},
"select count(Col3) where Col2 is not null group by Col1 pivot Col4")})

Use Query to display two columns and group rows based on one column's count?

I'm using an array to bring 2 columns of data together from 3 sheets.
There are duplicates in the second column, and I would like to group those duplicates together and display both Col1 and Col2, ordered alphabetically by Col1.
This is the formula I have right now:
=QUERY({'Sheet1!'A:B;'Sheet2!'A:B;'Sheet3!'A:B}, "Select Col1, count(Col2) where Col1 is not null group by Col1",1)
Which only displays Col1.
I've tried nesting QUERY, but I can't get it to work and can't find any direction anywhere online.
Here's an example sheet I made to show what I'm trying to do:
https://docs.google.com/spreadsheets/d/1_x0mXZC0ZjsHDCd6I0dDf9OI19lrzEcPYqfcMxuK74Y/edit?usp=sharing
In the example if an employee is listed twice the name may change but the email is consistent. I'm hoping to group by the email addresses and return only one name (it doesn't really matter which name).
I'm not sure if this is possible without formulas in more than one cell. Thank you either way!
#confuseddesk, try this array formula:
=ArrayFormula(QUERY({VLOOKUP(UNIQUE({Sheet2!B2:B;Sheet3!B2:B;Sheet4!B2:B}),{Sheet2!B2:B,Sheet2!A2:A;Sheet3!B2:B,Sheet3!A2:A;Sheet4!B2:B,Sheet4!A2:A},2,FALSE),UNIQUE({Sheet2!B2:B;Sheet3!B2:B;Sheet4!B2:B})},"Select * Where Col2 Is Not Null"))

Google Sheets import range returning incorrect data

The full google spread sheet system is used for score keeping and is prone to delays when updating, however I have never run into an issue like this were the same basic function is returning two separate results. The problem is repeatable and occurs on more than one spreadsheet.
I have created a test sheet-
https://docs.google.com/spreadsheets/d/1arh0D9ch5MpQjRh_bHjLfLx5S7TAW8R_pgGLf5tovig/
with the code in question; Can anyone help please?
=QUERY(IMPORTRANGE("***","***"),"select Col1 where Col1 <>5 order by Col9 desc")
in your QUERY formula you are selecting cells that are numeric and comparing it to <>5 but take a notice that A2 is not numeric:
that is the reason why 2 2 is not included in your C column
also it looks like that your QUERY formula smashed first cells into one because you did not specify the 3td query parameter. try:
=QUERY(IMPORTRANGE("1pnowvo6YVj-DZAPCaKE2x9vSIbpAAmlwhRMO2OZNlrE","color!A84:M115"),
"select Col1 where Col1 <>5 order by Col9 desc", 0)

How do I find the third most frequent value in google sheets

I am trying to find the third most frequent value in a google sheet. I saw how to find the second and first one, but I can't find out how to find the third and up. I need to know how to calculate the third, fourth, fifth, sixth, seventh, and eighth places. I am working on a leaderboard system for the school I work at.
I know this is how to find the second most frequent:
=ArrayFormula(MODE(IF((F1:F85=MODE(F1:F85)),"",F1:F85)))
and this is how to find the first:
=mode(F1:F65)
I need to find all the ones that come after that, though.
I need to find all the ones that come after that, though.
The more scalable solution that avoids nested IFs would be something along the lines of:
=ArrayFormula(QUERY({F1:F85,LEN(F1:F85)},"select Col1, count(Col2) where Col2 > 0 group by Col1 order by count(Col2) desc",0))
This produces a table of each number and their associated frequency, sorted from most frequent to least. You can retrieve the specific value from this table using INDEX:
=INDEX(QUERY({F1:F85,LEN(F1:F85)},"select Col1, count(Col2) where Col2 > 0 group by Col1 order by count(Col2) desc",0),n+1,1)
where n is the position you require (1 = most frequent, 2 = second-most frequent, etc).
Your initial This question was referring to a 2-dimensional range, which will be a bit more complicated, but still doable.
Given B1:B99 as our range, if A1 is most common, A2 is second most common, et cetera:
A1 = ArrayFormula(MODE(B1:B99))
A2 = ArrayFormula(MODE(IF((B1:B99=A1),"",B1:B99)))
A3 = ArrayFormula(MODE(IF((B1:B99=A1),"",(IF((B1:B99=A2),"",B1:B99)))))
A4 = ArrayFormula(MODE(IF((B1:B99=A1),"",(IF((B1:B99=A2),"",(IF((B1:B99=A3),"",B1:B99)))))))
I'm curious if anyone has a better solution though.
I'm pretty sure there is a more elegant solution to this than the other answers give.
Try using this Google Visualization API Query:
=query(A:B,"select A, count(B) group by A order by count(B) desc label count(B) 'Count' ",1)
This should give you 2 columns – the first gives the distinct values in your Column A, the second gives the number of occurrences for each value (sorted in descending order).
You should note that it seems that queries on single columns aren't supported, so I admit that the query is a little messy (although it should work if you just keep the B column empty).

Google spreadsheet Query Error - column doesn't exist

Another problem with Google Spreadsheet API. I'm trying to use QUERY() function in order to get all customers from our database who are from Warsaw. Google API seems however to have a big problem with parsing my query. I've checked it few times and everything is OK. Tried semicolons, different apostrophes and column names—it still won't work. I type this code in the sheet cell:
=QUERY(IMPORTRANGE("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!A3:G40"); "select B where E contains 'Warszawa'")
And get error like this:
Invalid query: Column [E] does not exist in table.
And I'm 110% sure that the column exists and the spreadsheet key is OK. ;)
If you are using the Query function with a direct reference to a rectangle of cells, then you use capital letters to refer to the columns. However, if you are using Query against the output of an array formula, such as the return from ImportRange, then you instead need to use Col1, Col2, ... to refer to the columns. So, your example query string would need to read:
"select Col2 where Col5 contains 'Warszawa'"
Working example:
=Query(ImportRange("0AtEH2Kw9zfIodEQ2dFNFam9sdEFEZlVnNEV3ZEZMZEE", "data!A:G"), "select Col3, count(Col4) group by Col3 order by count(Col4) desc label count(Col4) 'count'")
I've no idea why it doesn't just let you use names from a header row.
Alternatively you can try the FILTER function in this case and then you don't need to bother with SQL. :)
=FILTER(ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!B3:B40"); ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!e3:e40")="Warszava")
Although I admit that it's not so pretty because of the two importRange functions.
Hope it helped anyway.

Resources