Search code examples
google-sheetsgoogle-sheets-formula

Import data based on column first match column name


I use this to import data from another SHEET1:

=LET(data,importrange("MY_ID", "SHEET!1:1000"),
FILTER(data,IFNA(XMATCH(INDEX(data,1),{"timestamp"}))))

The formula works great, but I wanted to know if it is possible only to import the first Column that matches the name "timestamp"?

Because in some cases, I have 4-5 columns with the name "timestamp"...but I only need the FIRST always.


Solution

  • You can use INDEX to select one column based on the first match of the headers

    =LET(data,importrange("MY_ID", "SHEET!1:1000"),
    INDEX(data,,XMATCH("timestamp",INDEX(data,1))))
    

    Or, the same with CHOOSECOLS

    =LET(data,importrange("MY_ID", "SHEET!1:1000"),
    CHOOSECOLS(data,XMATCH("timestamp",INDEX(data,1))))