Both of these are reading right so I have the link and the sheet and all the info correct, it's just outputting a little strange. I believe it's the same issue on both of them. Any help much appreciated.
1st issue:
=query(importrange("link","b9:d1000"),"Select Col3 where Col1 = '"&C4&"' ")
When I do this one it needs two rows. It puts the value I want in the first one and leaves the second row blank. As in, if I put anything in the second row, it gives me #REF can't overwrite that cell.
2nd issue:
=query(importrange("link","b9:d1000"),"Select max(Col3) where Col1 = '"&C4&"' ")
When I do this one It gives me two rows: the word "max" and then below it the actual max value. How do I get it to give me just the max value
These are different issues. In the first, there happen to be two rows that meet the condition in where; the second of them has empty Col3. If you want only one result, either revise the where condition by adding some additional requirement, or put limit 1 at the end of query string, to make sure only one row is returned.
"Select Col3 where Col1 = '"&C4&"' limit 1"
Second issue: "max" is the name given to the output column. This name can be changed to empty string with label max(Col3) '', which will eliminate the cell with the name.
"Select max(Col3) where Col1 = '"&C4&"' label max(Col3) ''"
Related
Right now I am using this query to search for a row based on its Column 1 value. Then it takes the value from the last column. I need a way for it to automatically find the last column in the row since some of the rows have more columns than others.
This is what I had before, which I had manually specified the last column with a value:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select Col10 where Col1 = '5531001'",1)
I have tried using LOOKUP with ARRAYFORMULA I couldn't get it to work:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select (LOOKUP(1, ARRAYFORMULA(1/[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']<>"")[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']))",1)
Any ideas for a simpler way to do this?
Since no example is presented, I tested the formulas given but no source data is fetched.
so i created a a minimal, reproducible example
Example is the data on the left
Use this formula to get the last non empty columns values.
=ArrayFormula(IFERROR( REGEXEXTRACT( TRIM(TRANSPOSE(QUERY(TRANSPOSE(C3:E),,ROW(C3:E)))), "[^\s]+$")))
For each of the email id, I want to get latest 10 records by timestamp. How do I get the results with arrayformula? Query function is not important as long as I can still achieve this with arrayformula. Here is the sample data:
https://docs.google.com/spreadsheets/d/1YAHA02VM-5MXzVKhkxu_eODPKObpoz441mGX8lOFu5M/edit?usp=sharing
Try this on another sheet, row 1:
=arrayformula(query({query({Sheet1!$A:$C},"order by Col1 desc,Col2",1),{"Dupe position";countifs(query({Sheet1!$A2:$C},"select Col2 order by Col1 desc,Col2",0),query({Sheet1!$A2:$C},"select Col2 order by Col1 desc,Col2",0),row(Sheet1!$A2:$C),"<="&row(Sheet1!$A2:$C))}},"select Col1,Col2,Col3 where Col1 is not null and Col4 <= 10 order by Col1",1))
You can adjust the number of records found by adjusting Col4 <= 10, and also the final sort by altering order by Col1 at the end of the formula.
Explanation
This gets the data from Sheet1, sorts it by date desc then email asc:
query({Sheet1!$A:$C},"order by Col1 desc,Col2",1)
Then to the side of this data, a COUNTIFS() is used to get the number each time an email appears in the list above (since it's sorted desc, 1 represents the most recent instance).
countifs(<EmailColumnData>,<EmailColumnData>,row(<EmailColumn>),"<="&row(<EmailColumn>))
In place of <EmailColumnData> in the COUNTIF() is:
query({Sheet1!$A2:$C},"select Col2 order by Col1 desc,Col2",0)
In place of <EmailColumn> above, we only want the row number so we don't need the actual data. We can use:
Sheet1!$A2:$C
Various {} work as arrays to bring the data together.
Eg., {a,b,c;d,e,f} would result in three columns, with a, b, c in row 1 and d, e, f in row 2. , is a new column, ; is a return for a new row.
A final query around everything gets the 3 columns we need, where the count number in col 4 is <=10, then sorts the output by Col1 (date asc).
On second thoughts, maybe this is bit cheeky, but this might do it ( taken from conditional rank idea )
=ArrayFormula(filter(A2:C,countifs(A2:A,">="&A2:A,B2:B,B2:B)<=10,A2:A<>""))
EDIT
The above assumes (because the data is time-stamped) dups shouldn't occur. If they do and the data is pre-sorted, you can use row number as a proxy for time stamp as suggested by #Aresvik.
Alternatively, you could count separately
(a) only rows with a later timestamp
plus
(b) rows with the same time stamp but with earlier (or identical) row number
=ArrayFormula(filter(A2:C,countifs(A2:A,">"&A2:A,B2:B,B2:B)+countifs(A2:A,"="&A2:A,B2:B,B2:B,row(A2:A),"<="&row(A2:A))<=10,A2:A<>""))
I have added a new sheet ("Erik Help") with the following formula in A1:
=ArrayFormula({"Submitted Time","Email","Score";SORT(SPLIT(FLATTEN(QUERY(SORT(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(IF(Sheet1!B2:B=TRANSPOSE(UNIQUE(FILTER(Sheet1!B2:B,Sheet1!B2:B<>""))),Sheet1!A2:A&"|"&Sheet1!B2:B&"|"&Sheet1!C2:C,),,COUNTA(Sheet1!A2:A)))," ",0,1)),SEQUENCE(MAX(COUNTIF(Sheet1!B2:B,Sheet1!B2:B))),0),"LIMIT 10")),"|",1,0),1,0)})
The number of records is set after LIMIT.
The order is set by the final two numbers: 1,0 (meaning "sort by column 1 in reverse order," which, as currently set, is sorting in reverse order by date/time).
I am trying to transpose data from column A to single rows. The original data has 3 rows for each name. But there could be either 1 or several jobs for each day. Each day needs to be treated separately, but this maybe best handled by manually adding at the beginning of each day.
This is for a fortnightly timesheet, therefore the number of rows in unpredictable.
The 1st image is my original data. the 2nd is the desired end result.
The data is to transposed to any blank rows in columns b, c, d, e,
as long as there are no blank rows, I can then reference them with my formulas.
to place the information into the appropriate cells within
the timesheet. I already have working formulas to do this.
the transpose section is what I need help with
Here is a link to my file
https://docs.google.com/spreadsheets/d/1PhuFXDB2H1c9ua6szjhJEgJR91yXHhZAmn_2UGOBvIo/edit?usp=sharing
try:
=ARRAYFORMULA({QUERY(IF(REGEXMATCH(A12:A, "\d+:\d+.*"), VLOOKUP(ROW(A12:A),
IF(IF(IFERROR(RIGHT(A12:A, 4)*1)>2000, A12:A, )<>"", {ROW(A12:A),
IF(IFERROR(RIGHT(A12:A, 4)*1)>2000, A12:A, )}), 2, 1), ), "where Col1 is not null"),
QUERY(IF((IFERROR(RIGHT(A12:A, 4)*1)>2000)+(REGEXMATCH(A12:A, "\d+:\d+.*")),, A12:A),
"where Col1 is not null skipping 2"),
QUERY(QUERY(IF((IFERROR(RIGHT(A12:A, 4)*1)>2000)+(REGEXMATCH(A12:A, "\d+:\d+.*")),, A12:A),
"where Col1 is not null offset 1", 0), "skipping 2"),
FILTER(A12:A, REGEXMATCH(A12:A, "\d+:\d+.*"))})
If you want a solution with a formula in one cell only, try:
=arrayformula({"date","name","job type","start - end time";query(split(flatten(query(iferror(datevalue(A12:A),),"where Col1 is not null",0)&split(flatten(split(textjoin(char(9999),1,if(regexmatch(to_text(A12:A),":+.*-+"),A12:A&char(9998),if(iferror(datevalue(A12:A),)<>"",char(10001),A12:A))),char(10001))),char(9998))),char(9999)),"where Col2 is not null",0)})
in put B12 :
=IFERROR(if(FIND("2021",A12)>=1,0,""),B11+1)
in put C12 :
=if(B12=0,A12,C11)
in D12 :
=if(mod(B12,3)=1,TRANSPOSE(A12:A14),"")
and drag downwards. Then in F12 put :
=FILTER(C:F,F:F<>"")
and drag downwards.
Idea : use transpose() with a conditional counter. use (F12)filter to remove blank.
Please if it works/understandable/not.
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")})
I'm busy with creating an spreadsheet where I can get the average price of holidaydeals with a specific tag (f.e. a destination). When I do this for only one tag column the formula is working :) :
=averageifs(C4:C10,E4:E10,L1,F4:F10,"Frankrijk vakantie")
But... I have more then 10 tag columns in total and in every column something like "Frankrijk vakantie" could be found. My simple mind thought, okay lets change F4:F10 (in this example) to F4:G10 to look for "Frankrijk vakantie" in two columns. But... the formula didn't work.
Link to spreadsheet: https://drive.google.com/file/d/1Gw5VC5qT1bzbFIPBu5j4dLXBmJjh7GuW/view?usp=sharing
I've also added a screenshot. I hope that someone can help me with this. Would be great, thank you!
In L2 try
=query({C4:C11, ArrayFormula(N(mmult(N(F4:O11="Frankrijk vakantie"), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
and see if that works?
EDIT: to include a month/year filter try
=query({C4:C11, ArrayFormula(N(mmult(N( (F4:O11="Frankrijk vakantie")*(E4:E11=L1)), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
The formula makes use of a virtual array, containing the values of column C and the output of the mmult() function. The latter creates a column with 1's if 'Franrkijk vakantie' is found in that row AND the date in column E matches the date in L1. The query then averages the values from column C and filters out the rows where the conditions of the MMULT() are not met.
EDIT 2: To check for a 'double match' in the row, try
=query({C4:E11, transpose(query(transpose(F4:S11),,9^99))}, "Select AVG(Col1) where Col3='"&L1&"' and Col4 contains 'Frankrijk vakantie' and Col4 contains 'Europa vakantie' label AVG(Col1)''", 0)
Change range to suit.