How to join multiple cells grouped by values from a second column - google-sheets

I'm messing with this in Google Sheets.
I have two columns as shown in this image:
check out columns A and B picture
I would like to add a 3rd column "C", with joined values from column B depending if they are "Large", "Medium" or "Small".
For example, first cell in my desired 3rd column of joined values from my picture would be:
10,11,14
Because these values from column B match the same value on column A.
I hope I'm explaining well... I searched before posting here, but I really need a solution for that, and I think I'm missing something.

You could try something like
=TEXTJOIN(", ", 1, FILTER($B$2:$B, $A$2:$A="Large"))
or, assuming the word 'Large' is in A2:
=TEXTJOIN(", ", 1, FILTER($B$2:$B, $A$2:$A=A2))

Related

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

Google Sheets Query Coalesce?

is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.

Google Sheets: How to have the same values in column 4 whenever there are duplicate values in column 1?

The image explains what I would like to achieve probably the best:
The table I would like to create, at the moment I have only first three columns:
I would like the "New Volume" to have the same values whenever the keyword repeats. At the moment I have the three first columns but cannot figure out with what formula I can create the "New Volume" column.
I would appreciate the help.
This is a vlookup job.
=vlookup(D3;$D$3:$E$8;2;false)
It searches D column for identifier (also in column D) and returns value from second column. When vlookup is set as false, will always return first found value.
To avoid copying down the formula, you can nest it with arrayformula:
=ArrayFormula(ifna(vlookup(D3:D;$D$3:$E;2;false)))
My solution is here:
https://docs.google.com/spreadsheets/d/1RpSsb6DmUs6lcPmZ1R6uPW-a3iWs9XEnSpc3b3XiihI/edit?usp=sharing

Extract values from a range with 2 columns only if the value in column 1 contains a specific word in the column 2

I need to extract each individual person from a list that doesn't contain a certain activity (Project). Sounds easy but I can't quite get to the end of it.
Please check the example here on Sheet 2:
https://docs.google.com/spreadsheets/d/1qjbjXFCYj1qXrVVGNnhOj11asxT_o1xHWXerRqAl1UQ/edit#gid=2105763617
Here's the logic.
First I attempted to see if the individual only occurs once and if the Activity is not "Project"
=IF(A2<>"",IF(and(COUNTIF(A:A,A2)=1,B2<>"Project"),0,1),"")
Then I just extract the name that satisfies this criteria:
=query(ARRAYFORMULA(iF(I2:I=0,A2:A,"")), "where Col1 <>'' ")
This works, except there might be multiple assignments for the same person that does not contain the activity "Project" which my formula doesn't account for nor is it a simple dynamic arrayformula.
=UNIQUE(FILTER(A2:A, B2:B<>"Project"))
=UNIQUE(QUERY(A2:B, "select A where B <>'Project'", 0))
=UNIQUE(FILTER(A2:A, B2:B<>"Project",
NOT(REGEXMATCH(A2:A, "^"&TEXTJOIN("$|^", 1, FILTER(A:A, B:B="Project"))&"$"))))
While #player0's answer solves the question, it took a big performance hit on a sheet with >1000 rows.
Instead, I extracted all names that contained "Project" and then all names that did not contain "Project", then subtracted all the names from the first array to eliminate names that were in both.
=UNIQUE(FILTER(UNIQUE(FILTER(A2:A, B2:B<>"Project")), ISNA(MATCH(UNIQUE(FILTER(A2:A, B2:B<>"Project")), UNIQUE(FILTER(A2:A, B2:B="Project")),0))))
You may try this also:
{=IFERROR(INDEX($A$2:A$25,MATCH(0,IF($C$1<>$B$2:$B$25,COUNTIF($F$1:$F1,$A$2:$A$25), ""), 0)),"")}
N.B.
Cell C1 has criteria Project, using cell reference makes the formula
dynamic rather than hard coded.
Enter this formula in cell F2, finish with Ctrl+Shift+Enter,
and fill down.

Google spreadsheet creating unique IDs from informations in different columns

I want to create unique ID's for every items in a Google spreadsheet. This ID has to reflect informations contained in 2 columns. I made a simpler version of my data and joined it as an image WhereImAt. As you can see in the first column, I want people to be able to identify the "city", the "type" for each item in the spreadsheet and a number which make the entry unique.
The actual spreadsheet as more than 2k items in it. The column "city" has 19 possible entries and the "type" has 12.
For the moment the only formulas I can think of is "If()", but with so many variables, it looks impossible or way too complex. I'm sure there is something more efficient...
Can anyone think of a better way to achieve my goal?
Since the Cities will probably not all start with a unique character, you would need a table to look up the code for the city. Since you have a limited number of Cities and Types, you can use a table for each to validate the entries and look up the code. Assuming a table (sheet/tab) for each you could have a sheet called City and one called Type. City has the City Names listed in column A, starting at A2, and the associated Code in column B. Type has the Type listed in column A starting at cell A2, and the associated Code in column B. Both sheets use row 1 as a Header row.
So in your sheet, in cell B2, place this formula:
=CONCATENATE( VLOOKUP(C2, City!A2:B, 2, FALSE), "_", VLOOKUP(D2, Type!A2:B, 2, FALSE))
It will look up the City Name and the Type, returning the Code for each, and making a string which is CityCode_TypeCode.
Since you have many rows of data, you do not want to copy this formula for every row. This is where ARRAYFORMULA comes in. Unfortunately we cannot use CONCATENATE in an ARRAYFORMULA function, but there is an easy way around that. The more difficult part is using VLOOKUP, but with the trick used here, we can make that work. We will combine the strings using & and add an array to the third item of the VLOOKUP to get these to work. Last, I will use a little trick to place this in row 1 and still apply a header. For your Column B, you would place this in B1, and make sure the rest of the column is empty:
=ARRAYFORMULA(IF(ROW(C1:C) = 1, "ID", IF(ISBLANK(C1:C),, VLOOKUP(C1:C, City!A2:B, 2 * SIGN( ROW( C1:C ) ), FALSE) & "_" & VLOOKUP(D1:D, Type!A2:B, 2 * SIGN( ROW( D1:D ) ), FALSE))))
This only gets us to where you are currently with only one formula. To get to teh last step, I need assume the data will not be sorted, have rows inserted or deleted, etc. Is this one rule can be followed, the item in row 3 will ALWAYS be in row 3, we can get you to the last step using the Row Number by adding
TEXT(ROW(A1:A)-1, "0000)
to the mix to get a 4 digit number representing 1 less than the row so that our numbers start at 0001 So in your file, in cell A1, place this with nothing in the rest of the column:
=ARRAYFORMULA(IF(ROW(C1:C) = 1, "ID", IF(ISBLANK(C1:C),, VLOOKUP(C1:C, City!A2:B, 2 * SIGN( ROW( C1:C ) ), FALSE) & "_" & VLOOKUP(D1:D, Type!A2:B, 2 * SIGN( ROW( D1:D ) ), FALSE) & "_" & TEXT(ROW(A1:A)-1, "0000"))))

Resources