-1

I have these as strings: { column01 \ column02 \ column01 }(for other countries { column01 , column02 , column01 }). I want them evaluated as a array as if copy pasted.

array range

The array string range is created automatically, based on the selection of the user. I created a dynamically personalized dataset based on a sheet studeertijden named. The user can easily select the wanted tables by checkboxes, so by Google Sheets ARRAY range (formula). I try to copy these content to an other sheet ... to make the required data available for Google Data Studio.

The contents of page studeertijden is NOT important. Let's say, a cell in 'legende-readme'!B39 returns a string with the required columns/data in a format like this:

{ studeertijden!A:A \ studeertijden!B:B}

If I put this in an empty sheet, by copy and paste, it works fine :

={ studeertijden!A:A \ studeertijden!B:B}

How can it be done automatically???
my first thought was by indirect ...

What I've tried(Does NOT work):

Cell 'legende - readme'!B39 contains:

{ studeertijden!A:A \ studeertijden!B:B}
  • =indirect('legende - readme'!B39)
    returns :

#REF! - It is not a valid cell/range reference.

  • ={ indirect('legende - readme'!B39) } returns :

#REF! - It is not a valid cell/range reference.

  • ={'legende - readme'!B39}
    returns : { studeertijden!A:A \ studeertijden!B:B}

Note : For European users, use a '\' [backslash] as the column separator. Instead of the ',' [comma].

TheMaster
  • 45,448
  • 6
  • 62
  • 85
kris
  • 392
  • 4
  • 16
  • 1
    Do NOT share spreadsheets/images as the only source of data. Make sure to add input and expected output as **plain text table** (NOT as IMAGE/Spreadsheet LINK) to the question. [Click here](https://webapps.stackexchange.com/a/161855/) to create a table easily. Adding such tables makes **it is easier to copy/paste**. Your question may be closed, if it isn't [self contained](https://meta.stackoverflow.com/a/260455). Your table should be a minimal example.[Your email address can also be accessed by the public](https://meta.stackoverflow.com/questions/394304/), if you share Google files. – TheMaster Oct 29 '22 at 13:28
  • @player0 I'm not sure you get it. Your answer doesn't address how to get `=INDIRECT("{ studeertijden!A:A \ studeertijden!B:B}")`. I'll edit this question to clarify. – TheMaster Oct 29 '22 at 16:03
  • share a copy / sample of your sheet with an example of the desired output – player0 Oct 29 '22 at 20:26

3 Answers3

3

Assuming I've understood the question, if string doesn't need to start and end with curly brackets, then is this the behaviour you are looking for?

=arrayformula(transpose(split(byrow(transpose(split(string,",")),lambda(row,join(",",indirect(row)))),",")))

N.B. In my case I'm assuming that string is of the format 'studeertijden!A:A,studeertijden!B:B' (i.e. comma separated). So SPLIT by the comma to generate a column vector of references, TRANSPOSE to a row vector, INDIRECT each row (with the JOIN to return a single cell per row), ARRAYFORMULA/SPLIT to get back to multiple cells per row, TRANSPOSE back into columns like the original data.

This would be a lot easier if BYROW/BYCOL could return a matrix rather than being limited to just a row/column vector - the outer SPLIT and the JOIN in the BYROW wouldn't be needed. Over in Excel world they can also use arrays of thunks rather than string manipulation to deal with this limitation (which Excel also has), but Google Sheets doesn't seem to allow them when I've tried - see https://www.flexyourdata.com/blog/what-is-a-thunk-in-an-excel-lambda-function/ for more details.

The God of Biscuits
  • 2,029
  • 2
  • 3
  • 10
  • The idea is to use '**arrayformula**', also known as '**array literals**' in google sheet, _to_ _copy_ the data is NOT the correct word, **to reference to the original data** in a seperate sheet (so that it gets **automatically updated** if there're changes on the original sheet). It will be used as some kind 'column' filter. That sheet then can be used in _google_ _data_ _studio_ ... – kris Oct 30 '22 at 07:56
  • In the original post I referenced to 02 tutorials about '**arrays**' : - [How To Create Arrays In Google Sheets (a.k.a. Array Literals)](https://www.benlcollins.com/spreadsheets/arrays-in-google-sheets/) - [youtube: Google Sheets ARRAYFORMULA, Introductions to Arrays, ARRAY_CONSTRAIN, SORT Functions Tutorial](https://www.youtube.com/watch?v=m6-6Le7gEpY) Hope that explains my needs a little bit more. – kris Oct 30 '22 at 07:57
  • The formula I've given does specifically answer the question as per the title, in that it creates an array dynamically without copy/paste. It does also reference the original data and would automatically update, so I'm a bit confused by your comment. The basic issue you have here is that you cannot force-evaluate a string as an array literal in the way you would like, so you are compelled to use INDIRECT, but INDIRECT does not accept an array argument hence the need to use a LAMBDA+helper to build the array piecewise by an INDIRECT on each reference within the string. – The God of Biscuits Oct 30 '22 at 11:11
  • 1
    Just add ```{}\,``` to the split – TheMaster Oct 30 '22 at 12:51
  • 1
    Yes, this would work... But the OP appears to be generating the string by a formula based on some tickboxes, and is presumably adding the {}s as part of the formula to make the string look like an array literal - but it can't ever be evaluated as such so the {}s will always be redundant and it would make more sense not to generate the string to include them in the first place. – The God of Biscuits Oct 30 '22 at 13:45
  • reference [documentation](https://docdro.id/XXHysYy) -- Unfortunately ... this solution **ONLY seems to work for just ONE column**, 'VAK'. There are **missing columns** in this case 'STUDIEPUNTEN', 'PERCENTAGE'. – kris Nov 02 '22 at 07:02
0

Thanks to Natalia Sharashova of AbleBits, she provided this working solution (for the complete sheet).

referenceString is the reference to the string to all wanted columns; array matrix; { studeertijden!A:A \ studeertijden!B:B}

Note :

  • for European users, use a ' \ ' - [backslash] as the column separator
  • instead of the default ' , ' - [comma]

=REDUCE(
    FALSE; 
    ArrayFormula(TRIM(SPLIT(REGEXREPLACE( referenceString ; "^=?{(.*?)}$"; "$1"); "\"; TRUE; TRUE))); 
    LAMBDA(accumulator; current_value; 
        IF(
            accumulator = FALSE;
            INDIRECT(current_value); 
            { accumulator \ INDIRECT(current_value)}
        )     
    )
)
kris
  • 392
  • 4
  • 16
-2
={"1" , "2"}

={"1" \ "2"}

both are valid. it all depends on your locale settings

see: https://stackoverflow.com/a/73767720/5632629

with indirect it would be:

=INDIRECT("sheet1!A:B")

where you can build it dynamically for example:

=INDIRECT("sheet1!"& A1 &":"& B1)

where A1 contains a string like A or A1 (and same for B1)

another way how to construct range is with ADDRESS like:

=INDIRECT(ADDRESS(1; 2)

from another sheet it could be:

=INDIRECT(ADDRESS(1; 2;;; "sheet2")

or like:

=INDIRECT("sheet2!"&ADDRESS(1; 2))

for a range we can do:

=INDIRECT("sheet2!"&ADDRESS(1; 2)&":"&ADDRESS(10; 3))
player0
  • 124,011
  • 12
  • 67
  • 124
  • 1
    I putted a comment in the next post ... in the hope it explain my needs a little bit more. About your request to share the file, I have removed the link to a shared google sheet from the original post because of a remark of TheMaster (see comment on the original post) – kris Oct 30 '22 at 08:02