How to join the value of cells of a column, but only if a condition based in an other column is met - openrefine

In record mode, is it possible to join the value of cells of a column, but only if a condition based in an other column is met ?
Example :
With those data, in each record, join the values in col3 only for the rows where col2="yes"
Expected result :

Here is a solution in Python/Jython:
col2 = row.record.cells.col2.value
col3 = row.record.cells.col3.value
return ";".join([x for x,j in zip(col3,col2) if j == "yes"])
For Grel, the best solution is probably something like this (if you like russian dolls):
forEachIndex(row.record.cells.col3.value, i, v, if(row.record.cells.col2.value[i]=="yes", v, null)).join(";")
It is also possible to do that without formulas:
Switch to row mode
Text facet on col2, select the "yes".
On col3 (or a copy of col3): Edit cells / Join multivalued cells
On col3 again (or your copy of col3): Edit cells / Fill down

Related

Query returning 1st cell in range although condition is not met (Google Sheets)

I'm a first time query-user, so I'm out of my depth for fixing this myself.
Here's what I have and am looking to accomplish in two separate Google Sheets spreadsheets:
Spreadsheet1 - column A contains a list of names, column B contains a checkbox for true or false
Spreadsheet2 - import list of names from Spreadsheet1 column A where column B is true (and transpose the names so they appear in columns)
This is the formula I'm using in Spreadsheet2:
=TRANSPOSE(QUERY(IMPORTRANGE(LinkToSpreadsheet1,"Sheet1!A39:B51"),"Select Col1 where Col2 = TRUE",1))
The problem I'm facing is:
When column B in Spreadsheet1 contains only FALSE results, the formula is still returning cell A39 as the result, rather than returning no result.
I've also tested that when column B in Spreadsheet1 does contain a TRUE result (for example cell B48 = TRUE), but A39 is FALSE -- it is still returning cell A39 in addition to the matching TRUE cell of A48.
The problem I'm facing is:
When column B in Spreadsheet1 contains only FALSE results, the formula is still >returning cell A39 as the result, rather than returning no result.
that's because you use 1 as 3rd query parameter. you should use 0. try:
=IFERROR(TRANSPOSE(QUERY(IMPORTRANGE(LinkToSpreadsheet1,"Sheet1!A39:B51"),
"select Col1 where Col2 = TRUE", 0)))

spreadsheet missing data for corresponding cells

I have a problem with missing data of corresponding column.
Column A has unique value which corresponds to specific cities in Col B. But few cells in col B is empty. It is long spreadsheet. How to fill col B from the values of corresponding col A automatically?
enter image description here
You can use if condition available with syntax ISBLANK().

Google sheets query - I would like to return a column, but if cells in the column are empty return cells in another column instead

Kinda new at this, struggling with a solution.
So currently my formula looks like this:
=Transpose(Query(importrange("1XlxiJwGNEEgeV7qAbN4QXR1vustupeUMs5tOLI8qm54","2020 LNA!A:K"), "select Col8 where Col2 contains '"&P136&"' AND Col8 is not null offset 1"))
Col2 is my criteria and remains constant. What I'm looking to do is have the formula return the cell in Col9 if the cell in Col8 is empty. If the cell in Col8 is not empty it will just return as is.
Col8 is not null is to prevent returning empty spillover rows after the data.
Ideally I would use the case function but that isn't present for Sheets. Would love to hear any input, do let me know if more info/clarity is needed as well.
EDIT: Added pictures for reference. Image 1 is a separate workbook, Image 2 is desired output (E2:J2) with D1 as criteria
enter image description here
enter image description here
try:
=TRANSPOSE(QUERY(FLATTEN(QUERY(IMPORTRANGE(
"URL_or_ID_here", "2020 LNA!A2:C"),
"select Col2,Col3 where Col1 = '"&A1&"'", 0)),
"where Col1 is not null", 0))

How to lookup if my lookup data has duplicate values?

I am trying to lookup values from Table 1 to Table 2 based on Col1 in Table 1.
The catch is that Table 1 has duplicate values (for example, A is repeated 3 times) but I don't want to duplicate the returned value from Table 2.
How can this be done through either excel or sql (e.g. LEFT JOIN)?
What SQL are you using? Are you familiar with CTE and partition?
Have a look here: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/597b876e-eb00-4013-a613-97c377408668/rownumber-and-cte?forum=transactsql
and here: (answer and 2nd comment): Select the first instance of a record
You can use those ideas to create another field that tells you whether the row is the first, 2nd , 3rd etc occurrence of Col1. Eg you'd have something like
1 B Red 150
2 B Red 150
and you can then update col3 to be zero where this new field is not 1.
EDIT: since you asked about Excel: in Excel, sort by whatever criteria you may need (col 1 first, of course). Let's say that Col1 starts (excluding the heading) in cell C2. Set cell B2 =1. Then write this formula in cell B3:
=IF(C3=C2,B2+1,1)
and drag it all the way down. This will count the occurrences of col 1, ie it will tell you which is the first, 2nd etc time a given value appears in col1. You can then use it as as the basis to change the value in other columns.
Also, it is not good practice to have a column where the first cell has a different formula from the others. You can use the same formula nesting another IF and referencing the row, so as to set one formula for the first row and one for the others.

Splitting data into two columns

I have a very large Excel spreadsheet that looks like this:
However, I want to move every cell in the second column that starts with Location to the next column.
So it would look like this:
No need of VBA
Enter this formula in C2 and copy till last record
=IF(LEFT(B3,9)="Location:",B3,"")
Then copy paste values in column C, filter column B for Location:* and clear the resulting cells in column B or delete the rows (do as needed).
I would copy column B, paste it in column C then select C1 and press ctrl-- (CTRL and Minus together)
Select shift cells up and click OK.
Then either sort by column A or filter out any with a blank in column A.
You can also use this:
=IF(ISNUMBER(SEARCH("Location",B2)),B2,"")
Then apply conditional formatting to your data range as following:
Final Result