how to extract data from query in google sheet - google-sheets

i want to extract data from a google sheet query
QUERY(IMPORTRANGE("1HD5VhfUoCYq3fRcWQJSrkv1vxXEVdNeogho","A32000:Z"),"SELECT SUM(Col10),AVG(Col5) WHERE Col2='"&$B2&"' GROUP BY Col17 LABEL SUM(Col10)'',AVG(Col5)''",0)
I used this google sheet query to extract following data
revenue voltage
300 46.48
190 44.7
190 46.74
200 45.16
190 47.09
190 45.27
190 47.56
190 46.32
150 45.78
190 46.67
190 44.15
190 46.6
190 45.72
380 45.38
190 45.11
now i want to get voltage where revenue is 200 but withouot using other query
expected answer
revenue voltage
200 45.16

You can use another query to filter data based on revenue. Try below query.
=QUERY(QUERY(IMPORTRANGE("1HD5VhfUoCYq3fRcWQJSrkv1vxXEVdNeogho","A32000:Z"),"SELECT SUM(Col10),AVG(Col5) WHERE Col2='"&$B2&"' GROUP BY Col17 LABEL SUM(Col10)'',AVG(Col5)''",0),"where Col1=200")

Related

Google Sheets Formula for a range of answers

Trying to figure out a formula to automatically grade based on a range - for example, if the answer (number) in Column C is between...
70 - 94 = WTS
95 - 115 = EXS
116 - 140 = EXC
Sample data in column C:
76
96
95
123
115
I'd assume I'd put the formula in column D to get the outcome based on the range - so if the answer is between 70 and 94 I want column D to recognise this and put the response WTS. Following the rest of the ranges, I want to be able to use this formula for all data in the column.
Here is a link: https://docs.google.com/spreadsheets/d/1tLzm5u4tvWtDtNSxlN5COrkIm8w10_kyi7oobSzG5v8/edit?usp=sharing
Use XLOOKUP() function.
=XLOOKUP(C2,{70,95,116},{"WTS","EXS","EXC"},"",-1)
To spill results dynamically use XLOOKUP() with MAP() function.
=MAP(C2:C6,LAMBDA(x,XLOOKUP(x,{70,95,116},{"WTS","EXS","EXC"},"",-1)))
To refer full column as input try the following.
=MAP(C2:INDEX(C2:C,COUNTA(C2:C)),LAMBDA(x,XLOOKUP(x,{70,95,116},{"WTS","EXS","EXC"},"",-1)))
try:
=MAKEARRAY(COUNTA(C2:C),1,LAMBDA(r,c,VLOOKUP(INDEX(C2:C,r),INDEX({--REGEXEXTRACT(G:G,"^\d+"),REGEXEXTRACT(G:G,"[A-Z]+$")}),2,1)))
-

Formula to parse rows in google sheets and group them based on a column value

I have data like below in google sheets
A B C
1 82 54.73
2 20 58.32
4 78 57.84
3 21 58.58
2 20 55.05
3 20 54.55
1 20 49.63
4 21 43.65
2 33 43.65
5 19 45.87
In this column A can have repeated values
I want to list the rows with same column A values together and order by column B and get below output
A B C
1 20 49.63
1 82 54.73
2 20 58.32
2 20 55.05
2 33 43.65
3 20 54.55
3 21 58.58
4 21 43.65
4 78 57.84
5 19 45.87
Can this be achieved using google sheets. If so please suggest the formula to achieve same.
or try:
=QUERY(A1:C; "where A is not null order by A,B"; )
Use the SORT function. Like this:
=sort(A1:C10,1,1,2,1)

Getting a count of matched numbers in two series

My question is for Google Sheets
I am aware of the countif function and know how to count frequency of one value in a series but I am struggling to find frequency of multiple values in two series. I have tried countifs, arrayformula, countif + sum with and without array formulas but unable to succeed.
example
I have below series in E2:N2
31 32 35 45 49 55 57 66 72 75
and below series in O15:AH15
3 7 12 17 23 25 27 31 39 44 45 48 52 56 61 62 66 69 70 79
I want to see how many values matched and put that in cell A1
In the above example, 3 numbers matched so the value in A1 should be 3
I can do it with countif+countif+countif x 10 times but i wanted a very short formula.
Can someone give me some direction?
Thanks
Try
=SUMPRODUCT(TRANSPOSE(E2:N2)=O15:AH15)
This might serve you: Countifs in Google Sheets with various 'different than' criteria in same row adds +1 value
Basically is how to count based on criteria. there are even 2 sheets for you to check there and copy, you just need to change the criteria of words for the numbers you want to match and count.

How to make a request like: "limit(n-records) or as many existing records. AR is looping.

I have something I believe is very common and has a simple solution.
What I want is a request like...
"give me 10 records unless it's the end of records, then give me just the rest of results".
Consider a db-table with 105 records.
and a request like
User.first.foos.offset(100).limit(10)
This request will give me a result of...
recored: 100
recored: 101
recored: 102
recored: 103
recored: 104
recored: 105
recored: 1
recored: 2
recored: 3
recored: 4
recored: 5
What I want is just records 100, 102, 103, 104, 105
How can I make limit to not loop and give me records in the beginning?
Is it a RoR way to do this or do I have to count all records to and change the limit value based on the number of records?

Querying values from a Google Sheets

I have a table of foods with their nutritional values in a Google Sheets. My objective is to enter portions consumed of each food in a given day and calculate nutritional intake for the day. For each row that has a portion entered, I want to summarize the nutritional values times the number of portions served. I've given a very simplified version below.
Can anyone tell me how to go about doing this in Google Sheets?
PORTIONS FOOD CALORIES FAT PROTEIN
1 beef 250 34 25
chicken 220 22 13
carrots 20 12 23
2 beans 40 25 5
--------------------------------------------
TOTALS 330 84 35
In C6 place:
=sumproduct($A2:$A5,C2:C5)
Then copy across to D6 and E6

Resources