Address lookup after filter - google-sheets

I have a Google form and a spreadsheet that is supposed to process it. The spreadsheet needs to filter the responses by date and get their respective data after that.
E.g. Consider:
With the columns being A and B and the rows being 1-4.
How do I filter it by month in ascending order followed by adding the amount next to it?
So it would look something like:
I understand how to filter by month in ascending order. It is done using =SORT(FILTER(A:A, MONTH(A:A)=1)) (for Jan). But how do you get the data next to it? I have tried =INDIRECT(ADDRESS(SORT(FILTER(A:A, MONTH(A:A)=1)), 2)) but there is no error and it is blank.

You can do SORT for whole A:B instead of doing only for A:A.
Eg:
SORT(FILTER(A:B, MONTH(A:A)=1),1,TRUE) for Jan
SORT(FILTER(A:B, MONTH(A:A)=2),1,TRUE) for Feb
Please refer link here and see whether this is what you expect.

try this:
=QUERY(A:B,"select month(A), A, sum(B) where not A is null group by month(A), A")
or this:
=QUERY(A:B,"select day(A), sum(B) where not A is null group by day(A) pivot month(A)")
or you could use your formula =SORT(FILTER(A:A, MONTH(A:A)=1)) twice and use custom date format for first column to label it as JAN, FEB...

Related

How to 'count' only when header matches value?

I have a Google Form that collects a bunch of data from dropdown questions on a Sheet with each question going to one column (as normal). On separate sheets, I want to be able to count how many times each option is selected.
Here is an example of what the response sheet might look like. A, B, and C are all questions.
I would then have separate sheets for 'Person?', 'Place?', and 'Thing?'. The 'Person?' sheet would look something like this:
I want to be able to add in the count of each time the option appears for that question. In the example, notice that 'Napoleon" is in both Col A and Col C. If I just count the number of times 'Napoleon' appears, I will get '2' even though he only appears once in the "Person?" responses.
I originally used a QUERY function like =QUERY('Input Data'!1:1000, "select count(A) where A contains '"&$A2&"'",0). BUT, I need it to be dynamic. So the "Person?" question may not always be Col A. I want the Query (or whatever formula) to search the headers and only return the count of that option for that question even if the column location changes.
Okay, I figured it out! In case someone else is curious, I used this formula:
=QUERY({'Input Data'!A1:L}, "SELECT COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") WHERE Col"&MATCH("Person?", 'Input Data'!1:1,0)&" CONTAINS '"&$A2&"' label COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") ''",0)
Lee, I sent you a PM about your most recent post, but in the process, I came across this one. There is no need for multiple formulas or manual entry references. One formula can produce the entire report with headers, listing and counts:
=IFERROR(QUERY(FILTER(FILTER(A:L,A:A<>""),A1:L1="Person?"),"Select Col1, COUNT(Col1) GROUP BY Col1 ORDER BY Col1 LABEL COUNT(Col1) 'Count'",1),"No Matches")
Just fill in the header your looking for between the quotes where Person? is now.
The double FILTERs mean "Start with only rows where Col A is not null and Row 1 reads 'Person?'"
Then QUERY simply returns the unique names in the left column and their counts in the right column. Because the QUERY had a final parameter of 1, any existing header will be kept (in this case, the one you were searching for); and the created column will receive a header (i.e., LABEL) of Count.
IFERROR will give a friendly error message if no matches are found (in which case check that what you entered for the search in the formula exactly matches a column header in the range).

Google Sheets Query Coalesce?

is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.

How to seach column for all text matches in column A and sum all of the corrosponding values in column B Excel

I'm sure this is possible, but I've been trying various ways for the past 2 hours and can't find the solution.
I need to find all the instances of a text name in column A, lookup all the numerical results in column B and sum them together.
I thought =ArrayFormula(sum(lookup(F2,$A$2:$B$1000))) would do the trick, but it's only picking up the last value on the last mention and not all the values of all the mentions.
I've attached a spreadsheet to show the data I'm looking at.
Thanks to the reference from BigBen to check out Sumifs. Using this command, the following works a treat:
=SUMIFS(B2:B3115,A2:A3115,F2)
try:
=QUERY(A2:B; "select A,sum(B) where A is not null group by A label sum(B)''")

Google Sheet, Finance: FILTER twice to get only one cell

I have a Google Sheet with some stock information.
I'm using the formula GOOGLEFINANCE($B2, "price",TODAY()-15) to retrieve historical information about a stock (symbol named in $B2).
That returns a 2x2 table:
Date Close
8/25/2017 17:36:00 7.46
I only want the 7.46:
Using =FILTER(GOOGLEFINANCE($B2, "price",TODAY()-15),{FALSE; TRUE}) I get:
8/25/2017 17:36:00 7.46
I can't see to be able to nest FILTER twice.
I checked the documentation. Other than say that I should not use FILTER to filter columns and rows in the same call, I didn't get much out of it.
I gather a lot of stock information and always use index to get the stock price.
=index(GOOGLEFINANCE($B2, "price",TODAY()-15),2,2)
If you want the date use this. Be sure to format the cell as date or date/time.
=index(GOOGLEFINANCE($B2, "price",TODAY()-15),2,1)
For 2 filters try:
=FILTER(FILTER(GOOGLEFINANCE($B2, "price",TODAY()-15),{false;true}),{false,true})
I prefer query in this case:
=QUERY(GOOGLEFINANCE($B2, "price",TODAY()-15),"select Col2 label Col2 ''")
Also please try this formulas separately:
={false;true}
={false,true}
and see the result.

Google Sheets - Query - Running Total below dynamic results

Testing Sheet:
Wondering if there is a witty way to add a Total to the last row +1 of
a Query result.
See Sheet 'Lookup' for a static example of what I am asking for.
I don't know if there is a way to have a hidden column that calculates
transposed only under the last row of a query, or if there is a smart
way to work Query for this answer.
All great answers. Each on very useful in its use case.
Макс Махров gets the answer with using a query statement.
Now I was not keen on having an extra sheet to hold the totals so I added a row at the top which I can simply hide and used this formula:
query({Orders!A:E;A1:E1},"select Col1, Col3, Col4 where Col2 = '"&C3&"' order by Col4",1)
Only problem I have is trying to figure out how to add TEXT to the bottom row, it seems to only want numerical input.
How do I fix this? What am I glitching?
Thanks !
Mars
The trick is to make second query and count totals for selected product.
Plan of actions:
add new sheet with query on it, something like this: =QUERY(Orders!A:E,"select B, 0, sum(D) where B like '"&Lookup!C2&"' Group by B",0)
Prepare arrayformula which combines data in Lookup sheet: = ArrayFormula({Importrange(1),Importrange(2)}) Note that number of columns must retain the same.
Edit query so it takes Col1, Col2, Col3... instead of A, B, C...
Make word 'total' visible instead of zero. Set number format: 0;0;total Set it for range B9:B on Lookup sheet
Make Conditional Formatting with formula =and($B4 =0,isnumber($B4)) for range A4:C on Lookup sheet.
That's seems have to complete the task.
Hope it Helps!
Your Example
Working example.
Here is one way:
Put TOTAL way down in row 1000
Select the range A3:C999. Select data > filter to create filters
Select C3, set the filter to hide all blanks
A second way is to limit the query result to show only the top 8 results:
Change your query to =query(Orders!A:E, "select A, C, D where B = '"&C2&"' order by D desc limit 8",1) It will reverse-order column D (largest first), and set row limit to 8.
Change the formula of your TOTAL to =sumif(Orders!B:B,C2,Orders!D:D)
Try this formula in the column adjacent to your query:
=ArrayFormula({$C$4:offset($C$4,count($C$4:$C),0,1,1);sum($C$4:offset($C$4,count($C$4:$C),0,1,1))})
It duplicates your column of values (I haven't figured out a way around that yet) and then adds a total to the bottom of that column, and changes dynamically with the range from your query.
Here's a working version.
Interesting challenge! It got the old grey matter turning... ;)
Thanks,
Ben

Resources