I am importing ranges from other spreadsheets and filtering them using QUERY.
But I am trying to make my QUERY more resilient to changes, such as addition or removal of columns, as it can break when new columns are added or old removed. I'm using this formula
=LET(imp;IMPORTRANGE("sheet_url"; "sheet_name!A1:AA"); QUERY({imp}; "Select Col1 where Col"&MATCH(INDEX(IMPORTRANGE("sheet_url"; "GM");1); INDEX (imp;1);0)&" is not null";0))"
The formula is working but is not solving my current need. Any tip?
I am importing ranges from other spreadsheets and filtering them using QUERY.
But I am trying to make my QUERY more resilient to changes, such as addition or removal of columns, as it can break when new columns are added or old removed. I'm using this formula
=LET(imp;IMPORTRANGE("sheet_url"; "sheet_name!A1:AA"); QUERY({imp}; "Select Col1 where Col"&MATCH(INDEX(IMPORTRANGE("sheet_url"; "GM");1); INDEX (imp;1);0)&" is not null";0))"
The formula is working but is not solving my current need. Any tip?
Share Improve this question edited Mar 22 at 15:58 pgSystemTester 9,9872 gold badges27 silver badges57 bronze badges asked Mar 22 at 12:53 user30023146user30023146 1 1 |1 Answer
Reset to default 0To make it easier to refer to columns by name, use a named function or a lambda, like this:
=let(
data; importrange("..put sheet ID here.."; "sheet_name!A1:AA");
headers; chooserows(data; 1);
col_; lambda(colName; " Col" & match(colName; headers; 0) & " ");
statement; "select" & col_("Sales") & "where" & col_("GM") & "is not null";
query(data; statement; 1)
)
See named functions and lambda().
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744314477a4568111.html
1)
working but is not solving my current need
Please edit the question to explain exactly what is meant by this statement. Would you also read How to create a Minimal, Reproducible Example and then edit the question to include an MRE including sample data and an example of a successful outcome.2)
Query using column header as reference
This part of the question title is not referenced anywhere in the body of the question. Please remove it from the title or edit the question to explain how it is relevant to your problem. – Tedinoz Commented Mar 22 at 13:21