Search for a value in multiple columns and return all results that are in the right column of the found column - arrays

Search the value "thisisit" in column A and then search in this line for all "de" columns and return me what is in the columns to the right of it. If multiple results are returned, return the results in one cell but separate these results with a line break.
A1 | B1 | C1 | D1 | E1 | F1 | G1
thisisit | de | Bicycle | en | Car | de | Boot
A3
Bicycle (line break)
Boot

try:
=TEXTJOIN(CHAR(10), 1, QUERY({TRANSPOSE(FILTER(
INDIRECT(MATCH("thisisit", A1:A)&":"&MATCH("thisisit", A1:A)),
MOD(COLUMN(1:1), 2)=0)), {QUERY(TRANSPOSE(FILTER(
INDIRECT(MATCH("thisisit", A1:A)&":"&MATCH("thisisit", A1:A)),
MOD(COLUMN(1:1)-1, 2)=0)), "offset 1", 0); ""}},
"select Col2 where Col1 = 'de'", 0))

Related

ARRAYFORMULA, QUERY, and IMPORTRANGE is only displaying results for a single row

I am wondering if there is an issue with my formula because its not filling the entire column like an array should.
Currently my formula is working perfectly with B2, but its not working for the entire range B2:B.
Here is my formula:
=ARRAYFORMULA(QUERY({
{IMPORTRANGE("URL TO PRIVATE SHEET","$L2:$O")}
},"select Col4 WHERE Col1 CONTAINS " & $A2:A))
The IMPORTRANGE sheet looks like...
https://docs.google.com/spreadsheets/d/1GFnkuE3Dx-rTuvEV6wj1mCEq3P6cOxbzYco4aFVNw-I/edit?usp=sharing
| L |M|N| O |
| 000001 |*|*|JohnDoe#email.com |
| 000002 |*|*|JaneDoe#email.com |
| 000003 |*|*|BobDoe#email.com |
The ARRAYFORMULA is in B2
https://docs.google.com/spreadsheets/d/1JaWUWS3xKOwSX9y7uWUqEU5_Knp8nRgnhlVa1kRNlTo/edit?usp=sharing
| A | B |
| 000003 | BobDoe#email.com | <- Contains the formula above and works.
| 000001 | * | <- No data: should say "JohnDoe#email.com"
| 000002 | * | <- No data: "JaneDoe#email.com"
Is this a limitation in Google Sheets? Thanks!
you cant have array in 2nd argument of query like that. try perhaps:
=ARRAYFORMULA(QUERY({{IMPORTRANGE("URL TO PRIVATE SHEET", "L2:O")}},
"select Col4
where Col1 matches '"&TEXTJOIN("|", 1, A2:A)&"'"))
update:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY({
{IMPORTRANGE("1GFnkuE3Dx-rTuvEV6wj1mCEq3P6cOxbzYco4aFVNw-I", "L2:O")}},
"select Col1,Col4
where Col1 is not null", 0), 2, 0)))

How to TRANSPOSE this data in Google sheet for importhtml

I have data on a Google sheet. my importhtml formula get data in my sheet like this
Sheet one
Column A | | Column B
=================================
Name 1 | | Tom
Name 2 | | Dim
Want to data in this format
Column A | Column B | Column C | Column D
===========================================
Name 1 | Tom | Name 2 |Dim
| | |
Or in this format
Column A | Column B | Column C | Column D
===========================================
Name 1 | Name 2 | Tom |Dim
| | |
Please help me to archive data in a format in anyone from above
I try this but don't get format as I want
=TRANSPOSE(Importhtml(E1, "table",1))
or:
=SPLIT(TEXTJOIN("♦", 1, A:B), "♦")
and that would be:
=SPLIT(TEXTJOIN("♦", 1, IMPORTHTML(E1, "table", 1)), "♦")
try:
={TRANSPOSE(A2:A3), TRANSPOSE(B2:B3)}
and that would be:
={TRANSPOSE(INDEX(IMPORTHTML(E1, "table", 1),,1)),
TRANSPOSE(INDEX(IMPORTHTML(E1, "table", 1),,2))}

How to define range in importxml formula in Google Sheets

In my google sheet, I have URL in A1 and other data in B1, C1, D1, E1, etc... I want to use importxml formula but want to this work automatic, I mean in column B2 I try this
=ARRAYFORMULA( IMPORTXML($A1&$B1:$CZ1, "//suggestion/#data"))
so its do the rest of the job automatic I mean fetch data for A1and B1 in B2 and do A1 and C1 in C2 and A1 and D1 in D2, is it possible? I mean now I have to do manually enter formula in every column. hope you understand what I mean.
Column A | Column B | Column C
=================================
site.com | Name 1 | Name 2
| |
| |
| |
Column A | Column B | Column C
=================================
site.com | Name 1 | Name 2
| =ARRAYFORMULA( IMPORTXML($A1&$B1:$CZ1, "//name/#data"))
| |
| |
IMPORTXML is not supported in ARRAYFORMULA as you expect it. your options are:
paste in B2 and drag the formula to the right
=IMPORTXML($A1&B1, "//suggestion/#data")
paste in B2 the hardcoded formula for all columns:
={IMPORTXML(A1&B1, "//suggestion/#data"),
IMPORTXML(A1&C1, "//suggestion/#data"),
IMPORTXML(A1&D1, "//suggestion/#data")}
or scripted solution:
function onOpen() {
var sheet = SpreadsheetApp.getActiveSheet();
var length = sheet.getRange("B2:2").getValues().filter(String).length;
sheet.getRange("C3:3").clearContent();
sheet.getRange("C3:3" + length).setFormula(sheet.getRange("B3").getFormula());
sheet.getRange("C4:1000").clearContent();
}
where cell B2 is:
=ARRAYFORMULA(A1&B1:D1)
and cell B3 is:
=ARRAYFORMULA(IFERROR(IMPORTXML(B2:2, "//suggestion/#data")))

Find max of multiple columns (row-wise) and columns' names where max. values occurred (T-SQL)

I am fairly new to T-SQL and advanced concepts/queries and I have difficulty trying to figure out the situation described further. Lets say, I have a table like this:
--------------------
| K | C1 | C2 | C3 |
--------------------
| 1 | 14 | 24 | 48 |
| 2 | 10 | 65 | 37 |
| 3 | 44 | 90 | 22 |
--------------------
I need to find maximums row-wise, which has already been asked many times on SO, AND what makes difference, in addition, I also want the columns' names where found maximums occurred. The result has to be like this:
-- how to get Col column?
-----------------
| K | Max | Col |
| 1 | 48 | C3 |
| 2 | 65 | C2 |
| 3 | 90 | C2 |
-----------------
I learned how to find maximum rows-wise based on this and this threads, but I cannot understand how I could add another column containing columns' names where max. values occurred. I know I kinda have to show efforts but actually I cannot show anything since I just don't quite understand how to do it and all my attempts just return errors. Any ideas, hints? Thanks in advance!
The simplest way in SQL Server is to use apply:
select t.k, v.col, v.val
from t cross apply
(select top 1 v.col, v.val
from (values ('C1', t.C1), ('C2', t.C2), ('C3', t.C3)
) v(col, val)
order by val desc
) v(col, val)
I would approach this problem by joining a temporary maximum table back to the original and then writing a long "case when", assuming you have a reasonable number of columns. It would look like the following.
Select a.K
, b.Max_Value
, Case When a.Column_1 = b.Max_Value Then C1
When a.Column_2 = b.Max_Value Then C2
When a.Column_3 = b.Max_Value Then C3
... As Col
From Your_Table as a Left Join Max_Table as b on a.K = b.K
I believe this should get you what you want if I understood the question correctly. If you have a lot of columns where this would get too long then there's probably a better approach.

Normalizing a table by rank

I have a Table which looks like this:
Rank Account
| 1 | | A1 |
| 2 | | A2 |
| 3 | | A3 |
| 1 | | A4 |
| 2 | | A5 |
| 1 | | A6 |
In it all the Accounts which are linked together are ranked, done in a previous stored procedure. I want to now break down this table so that whenever a rank goes back down to 1 it takes the previous rows and writes it into a new table. for example Accounts A1,A2,A3 are all written into a separate table as are Accounts A4,A5 and Account A6. How would I do this.
The eventual goal being too right each table into a CSV file. Thanks!
In order to do this, you will need to add a third column to your table. This column would need to either be:
A grouping column that shows which Accounts are linked together, so that it will have the same value for A1, A2, A3. And another common value for A4 & A5, and another value for A6. Or
An ordinal column, such as an IDENTITY column, that you can use to tell in what order the Accounts were inserted, so that you can use that to figure out which items are grouped together.
Without a third column, there is NO WAY to know that A2 goes with A1 and not A4 or A6.

Resources