Sorting information in Google Sheets - google-sheets

I have some information in Google Sheets in the following format:
Authors
Number
Akwaeke Emezi
2
Ezra Claytan Daniels, Ben Passmore
3
Nick Tapalansky, Kate Glasheen
9
John Allison, Lissa Treiman, Whitney Cogar
1
John Allison, Lissa Treiman, Max Sarin, Whitney Cogar
2
Gene Luen Yang, Sonny Liew
43
Gene Luen Yang
9
I would like to have a second sheet that does the following:
Generate a list of each individual author in "Authors" (ideally in alphabetical order by last name)
Calculate the average Number associated with each author (e.g. Akwaeke Emezi would be 2 and Gene Luen Yang would be (43+9)/2)
I can do this as a one-off calculation, but what I'm really looking for is a way to set this up such that when I add more entries to the spreadsheet (where the new entries will contain a combination of new authors and authors that already appear in the list), this second sheet will automatically update the list of individual authors and their associated average numbers.

try:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
SPLIT(A2:A, ","), " (.*)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))
or:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
SPLIT(A2:A, ","), " (\w+)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))
update:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
TRIM(SPLIT(REGEXREPLACE(A2:A,
"\b(?:X)?(?:X)?(?:X)?(?:V)?(?:I)?(?:I)?(?:I)?(?:V)?(?:X)?(?:X)?(?:X)?\b", ), ",")),
" (\w+)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))

Related

Marking employees' names if detecting their time of working shifts are too close

I am designing a formula to warn the time of work shifts of the same employee conflicting. Based on the working schedule on A row to arrange the work shifts of every employee. The general working time is 3 hours. For an example of a picture, Andy in the table has arranged a shift at 2021/10/23 22:00, however, accidentally arranges andy works again at 2021/10/24 01:45, and his previous three hours work times have not been completed, which conflicts, so I hope to design that when his name is marked in the B row, it will be marked as a reminder. According to the picture, I originally designed an index and Match function in the D row to catch The names of employees with conflicting working hours are distinguished by V and X, but it seems that this group of functions cannot be successful. I would like to ask if there is a correct solution to solve it, thank you for your assistance.
add helper column:
=INDEX(IF(B:B="",,REGEXMATCH(B:B&COUNTIFS(B:B, B:B, ROW(B:B), "<="&ROW(B:B)),
TEXTJOIN("|", 1, "×", IF(0.125>IFNA(ABS(QUERY(
TRANSPOSE(SPLIT(FLATTEN(QUERY(QUERY(QUERY({1*A:A, B:B},
"select max(Col1) where Col2 is not null group by Col1 pivot Col2"),
"offset 1", ),,9^9)), " ")), "offset 1", )-
TRANSPOSE(SPLIT(FLATTEN(QUERY(QUERY(QUERY({1*A:A, B:B},
"select max(Col1) where Col2 is not null group by Col1 pivot Col2"),
"offset 1", ),,9^9)), " "))), 99), TRANSPOSE(SORT(UNIQUE(B:B)))&ROW(A:A)+1, )))))
you can change ranges to fit your needs just dont change last ROW(A:A)+1

Is there a way to use COUNTIF in Google Sheet to compare the occurrences of a value in ODD or EVEN increments for an inventory loan IN and OUT sheet

I am trying to use a Google Sheet to monitor the loan of inventory IN and OUT. There are several item numbers involved. There are two named ranges: ITEMIN and ITEMOUT. I tried using this formula:
=IF(ISBLANK(ITEMOUT),"--N/A--", IF(COUNTIF(ITEMIN, ITEMOUT)=0,"IN", "OUT"))
but it only registers correctly for the first cycle. Subsequent loan outs will be registered as IN. I have then tried this formula:
=IF(ISBLANK(ITEMOUT),"--N/A--", IF(ISODD(COUNTIF(ITEMIN,ITEMOUT)), "IN", "OUT"))
I tried to capture the ODD and EVEN occurrences of the item numbers to register the OUT and IN. For example: 1 occurrence (odd) of item no. 168 = OUT, 2 occurrences (even) of item no. 168 = IN and so on. The latter formula registered the OUT and IN in the following order for a particular item number: OUT->IN->IN->OUT->OUT->IN->IN instead of OUT->IN->OUT->IN
Really hope someone can help me with this as I am not really proficient in formulas or scripts.
Thank you in advance.
Actual worksheet:
Desired worksheet:
*NOTE: Attention to the item number 160 for both images.
based on your sheet this is the IN/OUT:
=ARRAYFORMULA({QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"), IF(ISODD(COUNTIFS(QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"), QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"),
SEQUENCE(COUNTIF({'CHECK OUT'!C2:H; 'CHECK IN'!C2:H}, "<>")), "<="&
SEQUENCE(COUNTIF({'CHECK OUT'!C2:H; 'CHECK IN'!C2:H}, "<>")))), "IN", "OUT")})

How can I get a QUERY to CONCATENATE text after it combines data?

On this sheet, I've been working on I have the info I need adjusting down into the Query Results
=QUERY(Investors!A4:D,
"select B,C,sum(D)
where B is not null
group by B,C
label sum(D)''")
How do I get the Stock Numbers Due that day to be listed out in column D? Like this:
1. 10/7/2019 Grady Johnson $100.12 PT-1013
2. 11/15/2020 Bill Jones $553.80 PT-1020, PT-1019
3. 11/15/2020 Grady Johnson $45.00 PT-1011
4. 11/15/2020 Steve Robinson $320.00 PT-1018, PT-1016
5. 11/17/2020 Jim Luke $1,057.20 PT-1009, PT-1008, PT-1007, PT-1006
6. 11/22/2020 Jim Luke $300.43 PT-1010
Here's the link: Google Sheet
Any help is appreciated!
or paste this in row 3 and drag down:
=JOIN(", ", IFNA(FILTER(Investors!A$4:A, Investors!B$4:B&" "&Investors!C$4:C=A3&" "&B3)))
try:
=ARRAYFORMULA(REGEXREPLACE(IFNA(VLOOKUP(TO_TEXT(A3:A)&" "&B3:B,
TRIM({TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({Investors!A4:C},
"select Col2,Col3,count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"select Col1,Col2 offset 1", 0)),,9^9)),
TRANSPOSE(QUERY(TRANSPOSE(IF(QUERY(QUERY({Investors!A4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"offset 1", 0)="",,
QUERY(QUERY({Investors!A4:A&",", Investors!B4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"limit 0", 1))),,9^9))}), 2, 0)), ",$", ))
Here is my suggested formula to be placed in Combined!D3 of your sample spreadsheet:
=ArrayFormula(IF(A3:A="",,SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(VLOOKUP(TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),{Investors!A:A,Investors!C:C&Investors!B:B},2,FALSE)=B3:B&A3:A,TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),))," ",COUNTA(Investors!A4:A))))," ",", ")))
As for how it works, that would be time-consuming to explain. (More time than is reasonable for a free site such as this.) I will suggest that, if this is important to you, take the time to study it. Take it apart and see what each piece does — separately and then in combination with other parts — until you've gotten it all back together.

I need to sum N highest players' score of each team

So I have a sheet like this
players:
and I need to get the sum of 4 highest scores of each team like this:
even when there are less than 4 players in a team (sum of 1, 2 or 3 best in these cases then) but without any scripts, I believe it's more than possible
try:
=ARRAYFORMULA({UNIQUE(SORT(FILTER(B2:B, B2:B<>""))),
MMULT(QUERY(SPLIT(TRANSPOSE(TRIM(QUERY(QUERY({9^9-C2:C&A2:A, B2:C},
"select max(Col3)
where Col2 !=''
group by Col1
pivot Col2"),,999^99))), " "),
"select Col2,Col3,Col4,Col5")*1, {1;1;1;1})})

Matching a dynamic array of rows to a dataset

So I have a large data set of products, (in my case, boxes of floor tiles).
each product has five related columns:
The product name ("Stone-Grey", "Cubic-Dark", etc)
The product series ("P-26", "D-25-A", "26-A-C", etc)
The warehouse where the product is stored ("P1", "D4", "A3", etc)
The shelf number where the product is stored ("1", "17", "25", etc)
The number of units within each box
There is quite a mess with the stock, and I need to rearrange some of it.
The problem is that the stock is dynamic, and I need my lists to be dynamic also.
My end goal is to list all the boxes with less than X items in the box and match all similar products (similar product = has the same name and series), and where exactly it's located (warehouse and shelf).
I've succeeded in creating the dynamic list of lacking boxes using The QUERY function, and also in creating a formula for the second part (matching all similar products, and their location).
The problem is it's a drag-down formula, and I need a dynamic formula, based on the size of the former list.
The first list is pretty much straight forward:
=Arrayformula(Concat(QUERY('Tiles_stock'!$A$4:AC$216,"Select A Where R < 0.13"),(Concat("_",QUERY('Tiles_stock'!$A$4:AC$216,"Select C Where R < 0.13")))))
The formula returns the warehouse and the shelf, matched together.
Now the tricky part, the second formula is:
=Textjoin(" , ",True, Arrayformula(Concat(QUERY('Tiles_stock'!$A$4:X$216,"Select A where N contains '"& O4 &"' AND O contains '"& P4 &"' AND R > 0.13 "),(Concat("_",QUERY('Tiles_stock'!$A$4:X$216,"Select C where N contains '"& O4 &"' AND O contains '"& P4 &"' AND R > 0.13 "))))))
Which works fine, but forces me to drag it down or up each time the first list has changed (as I said, it's a stock, and it's dynamic).
Here's an image of what I'm basically trying to achieve:
https://drive.google.com/file/d/1UIim9oFRyOqYZpzcg9VsYvzuffP6sQ7F/view?usp=sharing
Here's a link to the spreadsheet:
https://docs.google.com/spreadsheets/d/13q7EBz18z6t_iMVTT-M7fzcPjtdYligYjz_m90h_z3A/edit?usp=sharing
list all the boxes with less than X items in the box and match all similar products (similar product = has the same name and series)...
=ARRAYFORMULA(QUERY({QUERY(
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select Col1, count(Col1) group by Col1 pivot Col2", 0),
"select Col1", 0),
REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select count(Col1) group by Col1 pivot Col2", 0)),
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select count(Col1) group by Col1 pivot Col2 limit 0", 0)&",", )),,999^99))), ",$", )},
"offset 1", 0))

Resources