UNIQUE results sorted and grouped to multiple columns - google-sheets

Need your help with this.
I have the followuing data in google sheets
Google Sheets Sample file
Number
Name
1
Albert Stein
1
John Don
2
Jim Carter
2
John Don
2
Steve Mckeen
1
Mark Knoffler
1
Hellen Hunt
4
Mary Popins
3
Stewart Rod
4
Peter Pan
3
Christian
3
Bob Dylan
With this query:
=transpose(query(unique(A:B);"select Col1,Col2 where Col1 is not null order by Col1"))
I get :
Number
1
1
1
1
2
2
2
...
Name
Albert Stein
John Mcnamara
Mark Knoffler
Hellen Hunt
Jim Carter
John Don
Steve Mckeen
...
Your help will be much appreciated in order to obtain this result :
1
2
3
4
Albert Stein
Jim Carter
Bob Dylan
Mary Popins
Hellen Hunt
John Don
Christian
Peter Pan
John Don
Steve Mckeen
Stewart Rod
Mark Knoffler
I've been struggling with no success !
Thankx!!!!

Solution:
In D18 I entered
=transpose(arrayformula(iferror({sort(unique(A2:A)), split(regexreplace(trim(transpose(query(if((transpose(sort(unique(A2:A)))=sort(A2:A))*len(sort(A2:A)),sort(B2:B, A2:A, 1, 1, 1)&",",),,50000))),",$", ), ", ", 0)})))
References:
TRANSPOSE
ARRAYFORMULA
IFERROR
SORT
UNIQUE
SPLIT
REGEXREPLACE
TRIM
QUERY
IF
LEN

Related

How to create a formula that will repeat a range by splitting one column and joining with the other column?

I have 2 columns, first name and surname. I want to split a cell that contains multiple values and then combine it with the cell on the right. I have no idea how to do this using a formula, please help.
Before:
First Name
Surname
John,Jane,Mary
Fish
Albert,Steven,Alice
Smith
Expected Result:
First Name
Surname
John
Fish
Jane
Fish
Mary
Fish
Albert
Smith
Steven
Smith
Alice
Smith
use:
=INDEX(QUERY(SPLIT(FLATTEN(IF(IFERROR(
SPLIT(A1:A, ","))="",,SPLIT(A1:A, ",")&"​"&B1:B)), "​"),
"where Col2 is not null", ))
You can do this by looping over the range twice. First, loop over the range with REDUCE. Then SPLIT each of column A, then loop over each split of Column A and create a dynamic array using array literals: {}
=REDUCE(
A1:B1,
A2:INDEX(A2:A,COUNTA(A2:A)),
LAMBDA(a,c,
{
a;
REDUCE(
"💰",
SPLIT(c,","),
LAMBDA(
a_,
c_,
IF(
a_="💰",
{c_,OFFSET(c,0,1)},
{a_;{c_,OFFSET(c,0,1)}}
)
)
)
}
)
)
First Name
Surname
John
Fish
Jane
Fish
Mary
Fish
Albert
Smith
Steven
Smith
Alice
Smith

INDEX MACTH [Google Sheets]

I have a table with the result of a test. The table is structured as follows:
student score_description score_value
Juan test 1 5
Peter
Brian test 2 8
Jose test3 10
I need to convert this into a kind of pivot table using only formulas. For this, I thought of using the INDEX & Match but it doesn't work. At the end, I should see something like this:
student test1 test2 test3
Juan 5
Peter
Brian 8
Jose 10
Thanks a lot!
Try
=QUERY(A:C,"select A,sum(C) where A is not null group by A pivot B ")
or
=QUERY(A:C,"select A,sum(C) where B is not null group by A pivot B ")

How to extract unique rows based on a criteria across different sheets on Google Sheets

I have a main sheet with a lot of data but here it is simplified:
Manager
Employee
Project
Date
John
James
Pineapple
1/1/2021
John
James
Banana
1/1/2021
Alex
Robert
Apple
1/1/2021
Sally
Mindy
Kiwi
2/1/2021
Sally
Mindy
Orange
1/1/2021
Sally
Matthew
Tomato
2/30/2021
Sally
Mindy
Grape
1/1/2021
John
Vlad
Orange
2/30/2021
I tried using a formula that looks like this:
=ARRAYFORMULA(INDEX($B$2:$B,SMALL(IF($A$2:$A=B$1,ROW($A$2:$A)-MIN(ROW($A$2:$A))+1,""),ROW(B2))))
However it's not working.
I got the =UNIQUE() for each person from column A:
UNIQUE
John
Alex
Sally
I transpose this into their own columns:
John
Alex
Sally
and then I want a formula under each name that will go through the range that I specify
John
=UNIQUE() for column B "Employee" based on the criteria "John" in column A
=COUNTIF()
James
2
Vlad
1
And this would be useful to figure out the projects based on the criteria of column A "Manager"
John
=UNIQUE() Column C "Project"
=COUNTIF()
Pineapple
1
Banana
1
Orange
1
What's the best way of organizing this?
try:
=QUERY({A2:C}, "select Col3,count(Col2) where Col3 is not null group by Col3 pivot Col1")

Google Sheets - Sum unique rows in

In Google Sheets, I am trying to sum all values of a unique pair of rows and sort, for example:
Input:
Name -|- Last -|- Expenses
-=-=-=-=-=-=-=-=-=-=-=-
Bruce Wayne 100
Jack Napier 75
Bruce Wayne 50
Jack Napier 5
Selina Kyle 90
Output:
Name -|- Last -|- Expenses
-=-=-=-=-=-=-=-=-=-=-=-
Bruce Wayne 150
Selina Kyle 90
Jack Napier 80
I think this is what you want:
=query(A1:C6,"select A, B, sum(C) group by B, A
order by sum(C) desc, B, A
label sum(C) 'Expenses' ",1)
Here is a sample table:
https://docs.google.com/spreadsheets/d/1WeQZ3U8ZGziQiDZUoJbvF4cwFif16oePTq8jlICvL88/edit?usp=sharing
This sorts the records descending by amount, plus alphabetically by Last then First name.
Let us know if this doesn't answer your question.
Good luck.

In Google Sheets How do I get a sum of comma separated values in rows against an ID

I have a table which has a list of id's against names
Sheet 1
A | B
1 | Joe
12 | Dave
23 | Pete
I then have a table of rows which shows when a person was present at an event (through their ID)
Sheet 2
A | B
boston | 1
florida | 1,12
nyc | 12,23
In the 3rd sheet for appearances, I am then looking to achieve the following
Sheet 3
A | B (Appearances)
Joe | 2
Dave | 2
Pete | 1
I can get this to work when just one person makes an appearance with something like =COUNTIF(appearances!A:A, INDEX(name_db!$A$2:$A$1000, MATCH ($A11, name_db!$B$2:$B$1000, 0)))
But as soon as I add a comma value it all goes wrong.
I've tried looking into vLOOKUPS and things like that but can't seem to quite figure it out
Any help on where to look would be much appreciated
=ARRAYFORMULA(IFERROR(VLOOKUP(G:G, QUERY(VLOOKUP(TRANSPOSE(SPLIT(CONCATENATE(
IF(IFERROR(SPLIT(E:E, ","))<>"", "♦"&SPLIT(E:E, ","), )), "♦")), A:B, 2, 0),
"select Col1,count(Col1) group by Col1 label count(Col1)''", 0), 2, 0)))
This works for me:
=ARRAYFORMULA(IFERROR(SUM(SPLIT(D2;","))))

Resources