How can I get text from a cell using the select statement of the query function in Google Sheets? - arrays

I try to get some data from tab A to tab B using the query function. This all works fine untill I include some data of tab B into the object in the query function.
The thing is, I want to create a scoring sheet that calculates the constructor points based of the first sheet with the driver standings. So tab A looks something like this:
Peter Wright - Team Fast Racers - 85
Cameron Bright - Team Quickies - 60
Marc Feiner - Team Fast Racers - 20
In this example the number correspond to a total amount of points on the right column.
The second tab needing to calculate the constructor points, looks simply like this:
Team Fast Racers 105
Team Quickies 60
Don't look at the amounts. It is just an example.
Now I want to use the query code where I can ask Google Sheets to grab the constructor name from tab B (i.e. Team Fast Racers) and look it up in tab A to get the score from both drivers and sum it up to get the total. This is the syntax now:
=QUERY({'Driver Standings'!$A$4:$T$32; 'Constructor Standings'!A1:C16}; "SELECT T WHERE C = 'B2'", 1)
The problem is that it does not recognize B2 to get the 'Team Fast Racers' name and search for it in tab A. How can I fix this problem.
Again, 2 drivers are in a team and those scores need to be summed up and displayed in the second tab to get a clean constructor championship standings. How can I get the data from tab A based on searching for a string out of tab B column B.
And if that is all done, I would also like the constructor standings (tab B) to be sorted based on amount of points, without losing the structure of the formulas.

first of all, all ranges in { } needs to be of the same size (at least in one dimension). if you are stacking ranges one under another then amount of columns needs to be the same:
{Sheet1!A:C; Sheet2!A:C}
then when you have a "constructed range" as above, you need to use Col references in QUERY statement
so instead of
"select A,C"
it needs to be
"select Col1,Col3"
then if B2 is a numeric number it will be
"where Col1 = "&B2
but if it is a plain text it will be:
"where Col1 = '"&B2&"'"
UPDATE:
tho all you need is:
=QUERY({'Driver Standings'!C4:C\'Driver Standings'!T4:T};
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
order by sum(Col2) desc
label sum(Col2)''")

Related

How to use COUNTIFS based on multiple criteria over different sized ranges?

I have an attendance tracker in which I'm trying to account for each employee type per day.
I have a summary page (sheet1) in which I want the count of each type (A,B,C,D,E) based on the day in cell C2 whether or not they have an X on sheet2 for that day.
Using =COUNTIF(FILTER(Sheet2!$A$5:$GG$969,Sheet2!$A$5:$GG$5=$C$2),"X") I am able to get a total of "X" based on the date in cell C2.
However, I'm having trouble getting the formula to work counting each employee type.
=COUNTIFS(Sheet2!A5:AM31,A7,(FILTER(Sheet2!A5:AM31=C2)),"X")
This gives me an error "Array arguments to COUNTIFS are of different size."
I'm not sure how else to configure this. Below is a link to my sample sheet:
Appreciate any help!
https://docs.google.com/spreadsheets/d/1OdJTwbFsNcR1hO1qzMBGUY4iXcWgDwIAJmBAVE9cs0k/edit?usp=sharing
I think this would work, dragged down for the other groups.
=COUNTIFS(Sheet2!A$6:A$31,A7,FILTER(Sheet2!$6:$31,Sheet2!$5:$5=C$2),"X")
However, I would encourage you to look at this sample sheet (a copy of yours) where I've added a new tab called MK.Help, designed to be hidden, but used as a sort of helper tab to make all sorts of things you might like to do easier. Including the count you asked about.
It has one single formula in cell A2 where you can see what it does.
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(Sheet2!C5:5&"|"&Sheet2!A6:A31&"|"&Sheet2!B6:B31&"|"&Sheet2!C6:31),"|",0,0),"where Col3<>'' order by Col1"))
try:
={"", ""; QUERY(FILTER(Sheet2!A6:A31, FILTER(Sheet2!6:31, Sheet2!5:5=C2)="X"),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''");
"Total", COUNTA(IFNA(FILTER(Sheet2!A6:A31, FILTER(Sheet2!6:31, Sheet2!5:5=C2)="X")))}

How do you use ArrayFormula with arrays (after aggregation)?

In my example:
https://docs.google.com/spreadsheets/d/1QQNTw_r9-q-FqVNwUoYklup73niZCFyO0VDUYImP5fo/edit?usp=sharing
I'm using Google Forms as an eBay clone to sell rare items. Each bid is outputted from the form to the "Data" worksheet and then I have ArrayFormulas set up inside the "Processed" worksheet. The idea is that I want to process the bids so that we filter everything except the items with the highest bids. All data should be automatically updated, hence why I want to use ArrayFormulas.
My strategy is that in colum A, I first filter all unique items (=unique(filter(Data!A2:A,Data!A2:A<>""))) and end up with:
Jurassic Park 6-Pog Hologram Set
Princess the Bear TY Beanie Baby
Holographic 1st Ed Charizard
However, then in column B, we have to find the highest bid that corresponds to that unique item, e.g.:
=IF(ISBLANK(A2),,ArrayFormula(MAX(IF(Data!A2:A=A2,Data!B2:B))))
However, I don't want to have A2 be a single cell (A2) but an array (A2:A) so that it doesn't have to be manually copied down the rows. Similarly, I also want columns D and E to be automatic as well. Is there any way to achieve this?
Not sure if it would be considered easier than the previously posted answer, but in case this thread is found in the future, I think that this is a slightly simpler way to solve these kinds of problems:
Try this on a fresh tab in cell A1:
=FILTER(Data!A:D,COUNTIFS(Data!A:A,Data!A:A,Data!B:B,">"&Data!B:B)=0)
I did some research and found an answer very similar to what you were looking for. After rearranging the formula slightly to match your sheet, I was able to get this to work:
=ArrayFormula(vlookup(query({row(Data!A2:A),sort(Data!A2:C)},"select max(Col1) where Col2 <> '' group by Col2 label max(Col1)''",0),{row(Data!A2:A),sort(Data!A2:D)},{2,3,4,5},0))
This formula automatically populates product name, highest bid, username, and timestamp. I ran some tests, adding my own random names and values into the data sheet, and the formula worked great.
Reference: https://webapps.stackexchange.com/a/75637
use:
={A1:D1; SORTN(SORT(A2:D, 1, , 2, ), 9^9, 2, 1, )}
translated:
{A1:D1} - headers
SORT(A2:D, 1, , 2, ) - sort 1st column then 2nd column descending
9^9 - output all possible rows
2 - use 2nd mode of sortn which will group selected column
1 - selected column to be marged based on unique values

How do I sum values if both column, row and cell value match conditions?

I have two sheets: flight control and total hours control. Link to sheets.
Flight Control:
Total Hours:
What I want: On Total Hours, Sum the Flight Time if:
Column Name(L.D.1) matches row on Line; row Pilot matches row Pilot; cell has a value of 1.
I'm using this for cell C2, and it works:
=SUMIFS('Flight Time'!B:B;'Flight Time'!A:A;B2;'Flight Time'!C:C;"1")
And it works, giving me this:
However, this isn't very practical. I have to redo the formula every time a new pilot is introduced. And if I move columns around, it stops working.
What I need: To base my conditions on a text search. Something like:
If column name in {Flight Time!C:F} matches string on {row in col Line}, and Pilot = Pilot, and cell value = 1, SUM
In other words, I need to scale this. The final product will have dozens of pilots and L.D.s, so I need to be able to move things around.
My answer is similar to player0's but it anticipates a Flight Time tab that expands infinitely sideways as well as down.
You would start a new tab and place this formula in cell A1.
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(TRIM(SPLIT(QUERY(TRANSPOSE(QUERY('Flight Time'!C1:1&"|"&'Flight Time'!A2:A&"|"&OFFSET('Flight Time'!C2;;;ROWS('Flight Time'!C2:C);COLUMNS('Flight Time'!C2:2))*'Flight Time'!B2:B&CHAR(10);;9^99));;9^99);CHAR(10);0;0)));"|";0;0);"select Col1,Col2, SUM(Col3) where Col3>0 group by Col1,Col2 label Col1'Line',Col2'Pilot',SUM(Col3)'Total Hours'"))
Sometimes in complicated formulas like this, it can be difficult to translate to your real sheet if you haven't placed the sample data in exactly the same layout on the sample as it is on your real sheet. If that is the case here, change the layout of the sample so that it better matches your real data, and I can try to update the formula.
use:
=ARRAYFORMULA(SPLIT(
TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
IF(C2:F="",,"♠"&C1:F1&"♦"&A2:A&"♣♥"&B2:B),,999^99)),,999^99), "♠")), "♥"),
"select Col1,sum(Col2) group by Col1 label sum(Col2)''")),,999^99)), "♦♣"))

Excel, counting within a formulatext on array

Imagine rows A2:A11 = name of customer, Columns B1:AE1 = days of the month.
To make it easy:
Daily, we tally if customers purchase (quantity) and separate them with a + to get the total of that day purchase. (example: on 2nd day of the month (C2:C5)
Abe =44+54+10
John =22+10+40
Sara =40
Mary=10+10
Also we need to count total “sales cases” of the whole day (in the above example it is 3+3+1+2)= 9 to show in the last row of the day. (B12 in this example)
The logic is something like
=SUMPRODUCT(LEN(FORMULATEXT(C2:C5))-LEN(SUBSTITUTE(FORMULATEXT(C2:C5),"+","")))
But I’m getting NA.
reminder: when there are no "+" signs & the value is more than zero, it should count as 1.
help?
There is a trick to do this, which might end up a bit convoluted to achieve the end result you want
First, define a new name in Name Manager (in the Formula menu bar)
Name: FormulaText
Refers to: =GET.CELL(6,OFFSET(INDIRECT("RC",FALSE),0,-1))
Now if you have a formula in cell B3 of =10+20+30 enter =FormulaText in cell C3 and you will get the text version of the formula
You can now count + symbols in that formula using =LEN(C3)-LEN(SUBSTITUTE(C3,"+",""))
In your specific circumstances, I would offset all of this to the right of your spreadsheet, say by 35 columns, in which case you will need to change the definition of FormulaText accordingly.
A fair bit of set-up work, but the result should work automagically.

Excel quartile function with variable array criteria (like countif)

hoping someone can help with my Excel query.
I want to use the quartile function (or similar, could use percentile if that's easier). I have data in a column but I want to limit the data I use from that column.
I have job departments in column A, people's salaries in column B (and other data in the other columns e.g name).
I want to use my one main data list (c. 2,000 rows) to pick out the quartiles for the 10 or so depts I have but I don't want to have to make 10 specific lists to calculate the quartile of each dept.
Is there an option to use a countif or similar function so that I can have a drop down list of my 10 depts and depending on what dept I select my summary table will show the quartiles relevant for just that dept?
Thanks
Use an array formula =quartile(if(A1:A1000=C2,B1:B1000),.75) press control + shift + enter after entering the formula. Note: C2 = the department which quartile you are calculating.

Resources