How to define range in importxml formula in Google Sheets - arrays

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")))

Related

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

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))

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))}

Google spreadsheets query range get item to the right

I am trying to get data from a "flexible" sheet.
The idea is to add in a row a string, and next to it add a formula that from another sheet, it looks up the string and returns the cell just at the right.
Example:
Data Sheet: DataCollection
| | A | B | C | D |
| 1 | Pepper | 2 | Sugar | 5 |
| 2 | Carbon | 3 | Toy | 34 |
so if in my other sheet, the "Summary" I add to A1 Sugar I would like to see in A2 a 5.
What I have tried so far
VLOOKUP function
=VLOOKUP(A1,'DataCollection'!A2:B&'DataCollection'!C2:D,1,false)
didn't work! I keep receiving a parse formula error.
QUERY function
=QUERY(DataCollection, "SELECT B WHERE A = A1")
that does not work either, I need many different Named Ranges and add a different query for each of them.
Here is a test spreadsheet in case it explains better that my wall of text:
https://docs.google.com/spreadsheets/d/15L5nPGfZ8OXS5Rhl3PdIVhtF7D3QzerkARskflDiJL4/edit?usp=sharing
you almost had it. try:
=VLOOKUP(A1, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)
for an array use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)))

Excel: Sum up values of a table based on a condition or grouping from another table

I could not find exactly this problem, though it seems to be similar to this one: Conditional SUM using multiple tables in EXCEL except the fact that the rows will not always have the same sequence in the tables.
My results table (RES) shall be populated based on the Groups (A, B, C) of the Group Table and the values of Value Table.
I am grouping several Products into Groups A, B, C according to the
Group Table:
Products | Group
------------------------
P1 | A
P2 | A
P3 | B
P4 | B
P5 | A
P6 | C
For several periods I have the values that these products generate in different tables. These tables have the same column structure, for example:
Value Table Period 1 # Value Table Period 2
Products | Value # Products | Value
------------------------ # ------------------------
P3 | 40 # P2 | 60
P5 | 10 # P5 | 20
P2 | 60 # P1 | 10
P6 | 50 # P3 | 30
P1 | 20 # P6 | 40
P4 | 30 # P4 | 50
These values I am trying to consolidate into a Results table, which would sum up the different products according to their groups within the respective periods, as follows:
Result | Period 1 | Period 2
-----------------------------------
A | 90 | 90
B | 70 | 80
C | 50 | 40
I tried to apply the array concept of the other post, but I was not successful in adapting it to my tables, which differ in some structural aspects. I´d be happy if I could avoid the use of VBA.
Thanks a lot in advance!
after some additional efforts I found the right array formula, which should be put into the B2 cell of the Result table:
=SUM(SUMIF(Period1!$A$2:$A$7;IF(Result!$I$17:$I$22=Result!$A2;Result!$H$17:$H$22);Period1!$B$2:$B$7))
confirm with CTRL+SHIFT+ENTER and copy down and across.
I hope that this helps you, too ;-)
Here's another way...
=SUM(IF(ISNUMBER(MATCH(Period1!$A$2:$A$7,IF(Result!$I$17:$I$22=Result!$A2,Result!$H$17:$H$22),0)),Period1!$B$2:$B$7))
Using the semi-colon as a separator...
=SUM(IF(ISNUMBER(MATCH(Period1!$A$2:$A$7;IF(Result!$I$17:$I$22=Result!$A2;Result!$H$17:$H$22);0));Period1!$B$2:$B$7))
Note that the formula needs to be confirmed with CONTROL+SHIFT+ENTER.

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