GoogleSheets QUERY Formula Grouping - google-sheets

Having some trouble with this sucker. Trying to use QUERY function but want to exclude Column D from grouping. Data I'm hoping to see in each respective column of QUERY table:
Unique (non-duplicated) Names
Most Recent Move-In Date
Most Recent Check Date among those corresponding to "Most Recent Move-In Date" for each unique name
Check Amount Corresponding to that "Most Recent Check Date"
=QUERY(
A:D,
"select A,B, max(C), D where not B is null group by A,B,D label A 'Client Name',
B 'Move-In Date',max(C) 'Check Date',D 'Amount'"
)
What I've figured out so far is that including "Column D" in "group by" causes duplicate Names to appear, but without including that column in "group by" I get a "#VALUE!" error.
See link for sample data with examples: Data Test

Try the following on a copy of your demo spreadsheet.
On G15 add the following formula
=QUERY(
A:D,
"select A,max(B), max(C) where not B is null group by A label A 'Client Name',
max(B) 'Move-In Date',max(C) 'Check Date'"
)
On J15 write Amount
On J16 add the following formula
=ArrayFormula(vlookup(G16:G19&I16:I19,{A2:A11&C2:C11,D2:D11},2,0))

Related

New table which I can filter

Are there any tricks that could get me from table 1 to table 2. I don't see a solution at this time. Is it doable?
table 1
table 2
Thank you
I tried transpose and pivot but it doesn't help.
You can try this formula:
=query({BYROW(B1:B,lambda(each,if(each="","",XLOOKUP("class",INDIRECT("b1:b"&ROW(each)),INDIRECT("a1:a"&ROW(each)),,,-1)))),A1:C},"Select Col1,Col3,Col4 where not Col3 contains 'Class' AND Col2 is not null label Col1 'Class Name'",1)
It creates a first row (inside the formula itself with BYROW) with a XLOOKUP which finds the previous (or upper) Class (that's the final -1 in XLOOKUP), and then makes a QUERY of the 4 columns (1st with this Classes and the other three) filtering Type columns (not containing "Class"). If you want also to have the other column just add "Col2" after "Select Col1,"
See it working here
See if this is what you are seeking:
This formula will lookup the Name column for "Class A name" and "Class B name", and return the data between...
"Class A name" and "Class B name",
"Class B name" and end of data.
=LAMBDA(SOURCE,A,B,HEADERS,
LAMBDA(NAME,TYPE,NR,
LAMBDA(INDEXA,INDEXB,INDEXE,
LAMBDA(DATAA,DATAB,
{HEADERS;DATAA;DATAB}
)(FILTER(SOURCE,ROW(NAME)>INDEXA,ROW(NAME)<INDEXB),
FILTER(SOURCE,ROW(NAME)>INDEXB,ROW(NAME)<INDEXE))
)(XMATCH(A,NAME),XMATCH(B,NAME),COUNTA(NAME)+1)
)(INDEX(SOURCE,,1),INDEX(SOURCE,,2),INDEX(SOURCE,,3))
)(A1:C7,"Class A name","Class B name",{"Class name","Group name","Nr students group"})

QUERY Function: How to count with multiple counting criterias

[Goal]
I'm trying to count the number of tickets per employee in one column that has a status with either "Finished," "Finished (Scope)," or "Routed (Sales)" for a specific week. In another column I also want to count the number of tickets for a specific week without criteria. The data that I'm pulling from to count the tickets has the following column names.
Column A: Date,
Column B: Ticket ID,
Column E: Employee,
Column H: Finished Week
Column K: Week
In the formula, you'll notice that it's referring to cell H1, which the cell contains the current week which is this formula: =TODAY()-MOD(TODAY()-2,7)-1
[Current Formula]
=QUERY('Data'!$A$3:$J,"Select E,
COUNT(B) where D matches 'Finished|Finished \(Scope\)|Routed \(Sales\)'
AND H = "&H1&" GROUP BY E LABEL COUNT(B) 'Total Finished Tickets'",0)
[What it should look like]
I've created a sample spreadsheet that you can refer to.
Link: https://docs.google.com/spreadsheets/d/1MQLgt_SSbUIKv1rEwx-Y21hooxNOOgcUm_j1rFehHdg/edit?usp=sharing
[Issue]
I was able to create a table that counts the number of tickets per employee with the status as "Finished" OR "Finished (Scope)" OR "Routed (Sales)." Which is the "Current Result" table (Link: https://docs.google.com/spreadsheets/d/1MQLgt_SSbUIKv1rEwx-Y21hooxNOOgcUm_j1rFehHdg/edit#gid=0).
However, as I tried to add another count criteria, it gave me errors and I don't understand how to properly make this work. I wanted to look like the table of the title "Ideal Result" in the shared link. Can someone please help?
You can use the pivot clause to get a breakdown by the Status column like this:
=query(
Data!A3:J,
"select E, count(E)
where H = " & E4 & "
group by E
pivot D
label E 'Employee' ",
0
)
The downside is that the grand total must then be calculated separately, but that can be done with a simple sum() formula.
Alternatively, get the totals first, and then do a lookup to get the number of finished tickets, like this:
=query(
Data!A2:J,
"select E, count(D)
where H = " & E4 & "
group by E
label E 'Employee', count(D) 'Total new tickets' ",
0
)
=arrayformula(
iferror(
vlookup(
E12:E,
query(
Data!A2:J,
"select E, count(D)
where H = " & E4 & "
and (D = 'Finished' or D = 'Finished (Scope)')
group by E
label count(D) 'Finished tickets' ",
1
),
2,
false
)
)
)
Note that this serves just to illustrate how to aggregate the data into a report. Your question leaves it unclear as to which status values should be counted for each type of aggregation. No rows with status Routed (Sales) appear in the data, and I cannot see how the expected results you show could be derived from the data.
See your sample spreadsheet.
H1, which the cell contains the current week which is this formula
=TODAY()-MOD(TODAY()-2,7)-1
You may want to try the weeknum() function.
To get two independent counts, you can't use a Where clause because that would exclude cases from both counts, but you could use the fact that Query does not count empty cells something like this:
=ArrayFormula(query({if(regexmatch(D3:D,"Finished$|Finished \(Scope\)$|Routed \(Sales\)$"),true,),E3:E,if(K3:K>=H1,true,)},"select Col2,count(Col3),count(Col1) where Col2 is not null group by Col2 label count(Col1) 'Finished', count(Col3) 'New'",1))

Google Sheets query Select column concat with Select Count column

I help manage loot for a group in an MMO. I've created a google sheet to maintain visibility into who needs what items. The sheet basically works the way i want, but i'm having some trouble with returning SELECT A concatenated with SELECT COUNT(A). Honestly, i'm not sure how to go about it, but this is what i've got:
Right now I'm transposing
SELECT A WHERE C CONTAINS <VALUE>
which returns like this for multiple results:
Name OtherName OtherName
Meanwhile, the values (but not the format) i want to return, i can get with :
SELECT A, COUNT(A) WHERE C CONTAINS <VALUE> GROUP BY A LABEL COUNT(A) ''"
which returns:
Name OtherName
1 2
The desired output is:
Name(1) Othername(2)
The sheet is here:
https://docs.google.com/spreadsheets/d/1HUcgVg2ZFHteXhRnk2W2j_9RU4RvMd7nMTqCuRgmUdo/edit?usp=sharing
And the queries in question are on Sheet1. I put some example queries I've tried also in the sheet.
try:
=INDEX(REGEXREPLACE(QUERY(TRANSPOSE(IFNA(IF(B11>0, QUERY(GearList!A:C,
"select A,count(A)
where C contains '"&$D11&"'
group by A
label count(A)''", 0)), )),,99^99), " (\d+)", "($1)"))

How to select more than 2 columns in =QUERY()

I was trying to copy data from Sheet1 to Sheet2 using query. But I want to select MAX(A) and all the other columns where data exists (B,C,D...etc.) and group by B.
То clarify, in Sheet1 I have some similar rows which differ in col.A, which contains Timestamp, and a few other columns. I want to fetch only the latest record from each set of similar records.
So my Query is
=QUERY('Sheet1'!A3:S; "select MAX(A),B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S group by B")
It gives me error #Value! Unable to parse query string to FUNCTION query parameter 2 ADD_COL_TO_GROUP_BY_OR_AGG:C,...
The other columns need to be in the 'group by' to. See if this works
=QUERY('Sheet1'!A2:S, "select MAX(A),B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S group by B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S")
I used this function =QUERY('Sheet1'!$A$1:S;"select MAX(A) group by B label MAX(A) '' ";2) to populate the first column in Sheet2 and then for each column this function =ArrayFormula(LOOKUP($A$3:$A;'Sheet1'!$A$3:$A;'Имот'!B3:B)).
Basically the second function searches for match from the cell in column A in the same table with a cell in column A in the first table, gives the result of the current column and all this copies itslef in the whole column.
After that I copied the formula manually for each column. And my problem is already solved.

Group the data in one column per the values in another column

I have data something as below
email id subject of interest
ramesh#axito.com Java,C++
mnp#axito.com VB
ramesh#axito.com Python
mohan#axito.com Java,C++
mnp#axito.com JS
rohan#axito.com C#
But I need it in the format as below-
email id subject of interest
ramesh#axito.com Java,C++,Python
mnp#axito.com VB,JS
mohan#axito.com Java,C++
rohan#axito.com C#
Can someone please tell me how can I do this?
First, create the list of unique email addresses with =unique(A2:A). Suppose this is done in column C.
Then in cell D2, enter =join(",", filter(B$2:B, A$2:A=C2)) and drag this formula down columd D.
Explanation: filter keeps only the entries from column B with matching email; join joins them into a comma-separated list.
Try using query function:
=QUERY({A:B,A:B},"select Col1, Count(Col2) where Col1 <> '' group by Col1 pivot Col4")
Also try this formula, this is single formula solution:
={UNIQUE(FILTER(A2:A,A2:A>0)),TRANSPOSE(
SPLIT(
", "&join(", ",
ARRAYFORMULA(
if(query(A:B,"select A where not A is null order by A",0)=
query(A:B,"select A where not A is null order by A limit "&COUNT(query(A:B,"select A where not A is null",0))-1,1),"","|")
& query(A:B,"select B where not A is null order by A",0)
& " "
)
)
,", |",0)
)}

Resources