Google Spreadsheets ArrayFormula: How to split and transpose a cell-range? - google-apps-script

Hello everybody and thanks a lot for your help.
Here's my problem:
What I have:
I have a table with raw data in 53 rows and numerous columns which I would like to reduce and restructure into three columns: City, Date and Value.
https://docs.google.com/spreadsheets/d/1bsdC8lrtSGk957ae8Z0VRGnDqTZfFLPpLkfoid0UbIQ/edit?usp=sharing
What I've done so far:
For a single row, I used the following formula to make everything work as I wanted it to:
ArrayFormula({SPLIT(TRANSPOSE(Base_Data!A2)&"|"&TRANSPOSE(Base_Data!AJ1:1&"|"&Base_Data!AJ2:2),"|")})
What I want:
I'd like to extend the formula to work for the entire area, all 53 rows. Does anyone have a tip for this? The solution doesn't have to be a formula, it would work as a script, too

I've set up a new sheet called "New_Data [Erik]" and placed the following formula into A2:
=ArrayFormula(SPLIT(FLATTEN(Base_Data!A2:A&"\"&Base_Data!AJ1:1&"\"&Base_Data!AJ2:54),"\",0,1))
If this is a one-time conversion, I'd recommend copying the results in place. To do that, select A:C, hit Ctrl-C to Copy and then Ctrl-Alt-V to Paste Special. A small clipboard icon will appear. Click it and choose "Paste Values Only."
If you'll need this functionality ongoing, just understand that FLATTEN is a not-yet-official function of Google Sheets, which means that while Google sheets may very well make it official, they may also decide to do away with it at any time. (This is why I suggest copying and pasting the results in place, if it's just a one-time conversion.)

Not sure what you're trying to get to there. If you are trying to leave out all columns but 3, just do ={Base_Data!A2:A, Base_Data!E2:E} and add as many columns as you require comma-separated within the curly brackets

Related

Copy Adjacent Cells alongside Duplicate Cells

I have a very large Google Sheet spreadsheet that I need help with.
I have a long list of Network Switches that are very often repeated that I am trying to automatically copy the associated SKU into a separate adjacent cell.
My goal was, once the SKU is added the first time, whenever the same switch is added again, it will autopopulate with the same SKU.
For instance, C2461:C2463 are repeated, and once K2461 is populated, would like K2462 & K2463 to follow suit.
Any help would be greatly appreciated!
You can try this formula on Column L (col L will serve as a helper column):
=iferror(arrayformula(VLOOKUP(C2:C,C2:K,9,False)),"")
For now I can't seem to fit the formula without the use of a helper column (so I created a separate sheet for now that will serve as a database for the VLOOKUP formula) but this should get you started.
Sample using a helper spreadsheet (Database):
=iferror(arrayformula(VLOOKUP(Database!A2:A,Database!A2:B,2,False)),"")
Output:

Cut a portion of a cell value then edit and paste the results into a separate cell

I have a cell value that contains an address. I'd like to cut a portion of that data then edit and paste the results into a separate cell. I don't know the specific language to clearly outline my question so any help would be appreciated. I created annotated images to help.
Original .CSV data I imported into Google Sheets
The data from that import that I would like to extract within the cell.
Data output once I run the Macros script. Original cell data is copy, edited, and pasted into next column.
I have thousands of data entries like this so ideally this script would:
Cut all data starting at 'County:' from Premise Address column.
Paste that data into the County column while removing 'County:'
I ended up using the Split Text to Column function in sheets. Then Find and Replacing the remaining unnecessary text. It's not pretty but it worked.
Gonna dig into REGEXEXTRACT formulae tonight for some fun reading. Thanks!
There are multiple different ways to do this but the simplest would be to use the REGEXEXTRACT formulae; if the data structure is exactly the same across all samples, you could use the following one in the County column -
=IFERROR(REGEXEXTRACT(A2,"County: (.*)"))
Assuming that the first Premise Address is in A2 cell.

use JOIN to pull multiple IMPORTRANGES into SORT(ARRAYFORMULA({importrange1; importrange2; etc}

How can I use JOIN (and maybe VLOOKUP? FILTER?) to make a list of IMPORTRANGES, resulting in something like {IMPORTRANGE(C3,$E$1); IMPORTRANGE(C4,$E$1); IMPORTRANGE(C5,$E$1); IMPORTRANGE...}?
Currently, in a google sheet, I have a formula that looks like this: =SORT(ARRAYFORMULA({IMPORTRANGE(C3,$E$1);IMPORTRANGE(C4,$E$1);IMPORTRANGE(C5,$E$1);IMPORTRANGE..." where spreadsheet urls are in Col C and a range (same for every imported sheet) is in E1.
Typing it all in was fine when I only had about a dozen spreadsheets I was importing and they all already existed. But now I want to import many more spreadsheets (I heard that the limit of 50 importranges no longer applies) and they don't all exist yet. If I keep things as they are, every time I add another spreadsheet url to Column C, I'll also have to go in and edit my =SORT formula.
Then I found this thread, Fill ArrayFormula with dynamic ImportRange, which has a suggested answer listed as: ="=sort(ARRAYFORMULA({"&JOIN(";",ArrayFormula("IMPORTRANGE("""&VLOOKUP(FILTER(G2:G20,G2:G20<>""),Sheet3!$A$2:$B,2,0)&""","""&G1&"!A2:B"")"))&"}),1,True,2,True)"
The JOIN in there looks intriguing (I just recently learned about JOIN) but I don't understand all the syntax (like """) and I also can't access to original spreadsheet to see what the references point to.
So, I'm looking for help in how to input the C3, C4, C5, etc into the JOIN -- not sure how the VLOOKUP helps me -- and also if anyone knows why there are so many ="&=&"""s throughout the suggested formula...
One of the solutions below may do what you need. The first is what you requested. The second is the one which will probably work to combine multiple IMPORTRANGE formulas.
SOLUTION 1
="="&ArrayFormula(REGEXREPLACE(QUERY(UNIQUE(TRANSPOSE(SPLIT(CONCATENATE(IF(E3:E="","","IMPORTRANGE("&E3:E&", $E$1)"&":")),":"))),,9^99),"\)(.*?)I","\), I"))
SOLUTION 2
="=QUERY({"&ArrayFormula(REGEXREPLACE(QUERY(UNIQUE(TRANSPOSE(SPLIT(CONCATENATE(IF(E3:E="","","IMPORTRANGE("&E3:E&", $E$1)"&":")),":"))),,9^99),"\)(.*?)I","\); I")&"},""Select Col1 where Col1<>''"",0)")
You would then just copy the cell, select the destination cell and "paste as values" into the formula bar.
You can see the sheet in action HERE (just make a copy of it to use).

Google Sheets formula that includes values from another cell

In Google Sheets, I have a formula in a cell that connects to an API with a script and spits out the JSON results. For example, I can connect to the Youtube API with a formula that looks like this,
=ImportJSON("https://www.googleapis.com/youtube/v3/videos?id=mv-cj6mBkPk&key=API KEY&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics")
I'd like to make part of that formula get it's value from a separate cell. For example, the video ID above (mv-cj6mBkPk), rather than have it typed in the above formula, I'd like to pull in the value from a cell (i.e. B1). Then I can create multiple versions of this formula with other video IDs (i.e B2, B3, etc.)
I've tried combining various parts of the formula through CONCATENATE-ing a few cells, but that doesn't seem to 'RUN' the formula, it just shows it.
My skills aren't so advanced in this area, so any help would be great. Thanks!!
It is not obvious what your problem is exactly, or where you got the code for the ImportJSON() function (as this is not a built-in function),
but a variation of the below SHOULD work - if it does not, then post what error you are getting (exactly).
Also, I presume you have substituted "API KEY" for the actual key... I have used API_KEY, so that the formula does not get broken across multiple lines here.
A1 : mv-cj6mBkPk
A2 : =ImportJSON("https://www.googleapis.com/youtube/v3/videos?id="&A1&"&key=API_KEY&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics")

Referencing cell on other tab in formula

How to reference the same (row,column) on the different tab in the same google spreadsheet document?
So, I want to do something like this:
=SOME_FORMULA('First tab'!(ADDRESS(ROW(),COLUMN()))). This doesn't work.
If the formula isn't apsolutly referenced, entries of Google Forms questionnaire change the reference and mess up the formula. (the formula that looked at row number 5 after insert looks at row number 6) I can't use apsolute referencing ($A$1) because I have to enter it manually.
Can I change the reference on multiple cells? (for one I can use cmd + f4)
I had that annoying reference problem too. If I understand correctly you are trying to get the information on some cells, but every time someone sends information to the spreadsheet by filling up a Form, that reference moves down a row.
The best solution I came up with was to create a new SpreadSheet and import all the information with this:
=importrange("spreadsheet-key","Form Responses!A1:B2107")
That function updates the info in realtime, so you can do all the processing on the new spreadsheet.
Hope this helps.
Do not quite understand what you need. Need to reference a cell in another sheet given coordinates on the current cell where it is located?
If so, the following formula can be useful:
=INDIRECT("First tab!"&ADDRESS(ROW(), COLUMN()))