Vlookup to Make a list? - google-sheets-api

This site has been super helpful, thank you to everyone who has answered my questions. Here is the next one I am working on. Not sure if I should use vlookup, hlookup, a combination of both or something else.
So I have a list of teams with lineups
Team
Player
A
Sam
A
Chris
A
Tom
A
Scott
B
Mark
B
Dan
B
Greg
B
Ben
C
Sara
C
Beth
C
Luara
C
Britt
On a separate page I am trying to fill in a line up "IF" a team is selected.
For reference this is the current formula I have been trying:
=IFERROR(INDEX('Team LineUps'!$B:$B,Match(0,COUNTIF($C$16,IF('Team LineUps'!$A:$A=$C$16,'Team LineUps'!$B:$B,$C$16)),0)),"")
This will get me The first player on the list for a team. If I change the 0 to a 1 it will get me the last player on the team. How can I/ Can I? get the entire list 1-4? Or is it only a "true" OR "False"

Answer:
Use a QUERY.
Formula:
=QUERY('Team LineUps'!A2:B13, "SELECT B WHERE A='"&B4&"'")
Example Usage:

Related

Concatenate rows across multiple columns in Access 2013 using VBA

I've an Access database that follows each Line Item across multiple stages where tasks are assigned to individuals. Each stage has a Comments field and are recorded in a Table which looks like:
Line Item Stage Title Comments
1 1 Introduction Trial comment
1 1 Introduction Another one
1 2 Abstract Following one
1 2 Abstract Andi nexto
1 3 Thesis Nexto
2 1 Introduction Comment for next item
2 1 Introduction Andi another one
...
I want to be able to concatenate these comments for each stage and each Line Item as:
Line Item Stage Title Comments
1 1 Introduction Trial comment, Another one
1 2 Abstract Nexto one, Andi next
1 3 Thesis Nexto
2 1 Introduction Comment for nexto item, Andi another one
I tried using Allen Brown's ConcatRelated() function with multiple WHERE criteria:
ConcatRelated("[Comments]","[CommentsT]","[LineItemNo]=" & "[txtLineItemNo] AND "[StageNo]=" & [txtStageNo])
but with no luck. Using a single WHERE clause does concatenate all the comments in the required field without considering StageNo and Title.
Kindly advise as to what is the best way for me to achieve this.
Thank you.

Compare last row to previous row by group and populate new column

I need to compare the last row of a group to the row above it, see if changes occur in a few columns, and populate a new column with 1 if a change occurs. The data presentation below will explain better.
Also need to account for having a group with only 1 row.
what we have:
Group Name Sport DogName Eligibility
1 Tom BBALL Toto Yes
1 Tom BBall Toto Yes
1 Tom golf spot Yes
2 Nancy vllyball Jimmy yes
2 Nancy vllyball rover no
what we want:
Group Name Sport DogName Eligibility N_change S_change D_Change E_change
1 Tom BBALL Toto Yes 0 0 0 0
1 Tom BBall Toto Yes 0 0 0 0
1 Tom golf spot Yes 0 1 1 0
2 Nancy vllyball Jimmy yes 0 0 0 0
2 Nancy vllyball rover no 0 0 1 1
Only care about changes from row to row within group. Thank you for any help in advance.
The rows are already ordered so we only need to last two of the group. If it is easier to compare sequential rows in a group then that is just as good for my purposes.
I did know this would be arrays and I struggle with these because never use them for my typical sas modeling. Wanted to keep things short and sweet.
Use the data step and lag statements. Ensure your data is sorted by group first, and that the rows within groups are sorted in the correct order. Using arrays will make your code much smaller.
The logic below will compare each row with the previous row. A flag of 1 will be set only if:
It's not the first row of the group
The current value differs from the previous value.
The syntax var = (test logic); is a shortcut to automatically generate dummy flags.
data want;
set have;
by group;
array var[*] name sport dogname eligibility;
array lagvar[*] $ lag_name lag_sport lag_dogname lag_eligibility;
array changeflag[*] N_change S_change D_change E_change;
do i = 1 to dim(var);
lagvar[i] = lag(var[i]);
changeflag[i] = (var[i] NE lagvar[i] AND NOT first.group);
end;
drop lag: i;
run;
It is not uncommon for procedural programmers to find this kind of dilemma in SQL, which is predominately a set language where rows have no position. If you write a procedure that reads the select data (sorted in the desired order), it can have variables to control creating the desired additional columns in the output, similar to the lag function above.
Or you can put it into a spreadsheet, which is happier detecting the changes in formula filled columns =if(a2<>a1,1,0). Just make sure nobody re-sorts the spreadsheet data into a new order!

Maximise the number of new encounters between guests at a meeting

I am hosting a series of meetings. There are 24 guests. Two or three times each meeting, we break out into different subgroups of between 2-6 people. I would like to maximise the new encounters so I am looking for an algorithm to help me make new matches, so everyone can meet everyone else.
My current idea is to record the data in Google Sheets and then use the QUERY function to analyse the data. (QUERY is very similar to SQL syntax.)
Here's the 'Round1' table:
subgroup1 | subgroup2
==========|==========
Adam | Edith
Ben | Fran
Chris | Gary
Dave |
And the table for 'Round2' looks like this:
subgroup1 | subgroup2 | subgroup3
==========|============|===========
Adam | Ben | Dave
Gary | Fran | Edith
Chris | |
What I want to do is consume that data and output a chart like this which shows me who has met whom:
Adam Ben Chris Dave Edith Fran Gary
Adam X TRUE TRUE TRUE FALSE FALSE TRUE
Ben TRUE X TRUE TRUE FALSE TRUE FALSE
Chris TRUE TRUE X TRUE FALSE FALSE TRUE
Dave etc...
Edith etc...
Fran etc..
Gary etc...
Could anyone help me to think through how I can use QUERY/SQL to turn those input tables into that output chart?
If you look in cell B3 on the new tab on your shared sheet called MK.Help, you'll find this single formula:
=ARRAYFORMULA(IF((B2:2="")+(ROW(A3:A)>COLUMN(B2:2)),,COUNTIF(QUERY(TRANSPOSE('One table'!A:E),,9),"*"&A3:A&"*"&B2:2&"*")+COUNTIF(QUERY(TRANSPOSE('One table'!A:E),,9),"*"&B2:2&"*"&A3:A&"*")))
That is telling you the counts for a heat map based on the tab called OneTable and nothing else. It will self populate indefinitely as you add groups to the OneTable tab.
Is that what you're going for?
I have come up with an answer, with a very laborious process! Maybe if I explain it here, someone can help me think how to make this simpler.
I start with the example data in this sheet.
In the original question I described one table per round, but I don't care in which round someone met, so I can combine all that data into one table. So in this table, each row shows one of the subgroups:
Then I do a long sequence of match(), transpose(), filter(), join(), split(), until I get this table which shows who has met whom:
From there, it is not so hard to generate the output chart I was looking for
This works! But it is not very elegant. I will love to make this simpler.

Compare multiple values based on cell Value

I have a 3 datasets.
Master dataset have
A B C D
11 T Jim India
12 U Mary UK
13 V Bob US
14 P Peter India
India dataset
A B H K
10 11 T Jim
10 13 0 Krestel
10 14 P Peter
10 15 L Robert
If the D coulmn had India then the details of columns A, B and C should match that in India dataset with coulmn B, H and K respectively. (The combination of the column A, B and C should present in Dataset- India, If not hoghlighted or add comment in last column of master dataset)
I have been doing this manually by adding several helper columns in all the datasets using concatenation and then using vlookup.
Is it possible to automate this process using vba?
Any help will be appreciated.
Actually, I think that you can achieve this through spreadsheet functions alone, without the need of VBA. Check the usage of the function VLOOKUP.
The idea would be to deploy a formula in, say, column "E" of the Master dataset that would check for an entry in the relevant country dataset matching the values of A, B and C. You will need to build the reference to the range VLOOKUP uses taking into account the country name.
Hope this serves you as a good guide.

How do I tally how many times a word appears on a certain row?

I have four sets of data representing a softball schedule. Looks like this:
Day Team 1 Team 2
M A Team B Team
T C Team D Team
....
but four times over. I want to be able to change the schedule and have it automatically tally how many times a team plays on a given day. Ideas?
You would us something like this:
=COUNTIF(2:2,"A Team")
Edit:
You can use a SUMPRODUCT() Function with math operands * and +:
=SUMPRODUCT(($A$2:$A$43=H$1)*(($B$2:$B$43=$G2)+($C$2:$C$43=$G2)))
So how it works:
Since TRUE/FALSE is a Boolean and it can be reduced to 1/0 respectively. Using the * and + operands is like AND and OR respectively.
The SUMPRODUCT iterates through the range and test each criterion inside the () So it first test whether the cell in column A is equal to H1, if so it returns a 1, or a 0 if not. the next part sets up the OR if in the same row the team name is found it also returns a 1. 1 * 1 = 1. SUMPRODUCT keeps track of all the 1 and 0 and adds them together, so you get the count.
If there are other columns that have the team names just add those columns with the + area.
Ok, so let's start with making your table a real table via "Start > format as table" and call your table "data". Then you have three columns called data[Day], data[Team 1] and data[Team 2]. For instance this:
Day Team 1 Team 2
Monday A Team B team
Tuesday C Team D Team
Wednesday C Team A Team
Monday B Team C Team
Now comes the ugly part. You need a matrix of 7*10 (days * teams)
(Cell E1) Team 1 Team 2 Team 3 Team 4 ...
Monday *1
Tuesday
Wednesday
...
Formula *1
=SUMPRODUCT((data[Day]=$E2)*((data[Team 1]=F$1)+(data[Team 2]=F$1)))
Now drag down that formula till Sunday and then copy it to the other teams (when I tried dragging it to the other teams, Excel messed up the column names!).
This will automatically fill the matrix and tell you which team plays how often on a specific day.
What does it do? Basically SUMPRODUCT can not only build products, but it can also evaluate boolean conditions. So if on Monday, Team A plays, then the first column would return (for Team A / Monday):
1*(1+0)
SUMPRODUCT does that for each line in the matrix and then sums up the result.