Forum Discussion

dr-numbers's avatar
dr-numbers
Copper Contributor
Jun 30, 2025
Solved

Splitting Array Elements into Multiple Elements

I am trying to extract an array from a column of a table. The column is text only and some cells have multiple values separated by semicolons. I am trying to extract an array that has a separate item per array element.

Using this formula, I get an array where each cell in the table column is an element of the single column array with duplicates removed and sorted alphabetically.

=SORT(UNIQUE(GPO[about:config setting equivalent],FALSE,TRUE))

This is one of the elements in the array but it is three values separated by the two semicolons.

browser.download.dir;browser.download.folderList;browser.download.useDownloadDir

There are many elements that have only one value but there are others that have two, three, four, or more values.

Is there a way that elements with multiple values can be split so each value is a separate element? My best guess it that it is a function  that operates on the GPO[about:config setting equivalent] array within the UNIQUE function. I just have no clue as to what that function would be or even if such a function exists.

Each value contains no whitespace and it is not difficult to change the delimiter from a semicolon to a space or a comma if necessary.

  • if it is a small set you can get away with 

    =UNIQUE(TEXTSPLIT(TEXTJOIN(";",,GPO[about:config setting equivalent]),,";"))

    but I'm guessing that is not the case so you will probably need this:

    =UNIQUE(DROP(REDUCE("",GPO[about:config setting equivalent],LAMBDA(p,q,VSTACK(p,TEXTSPLIT(q,,";")))),1))

    that said I notice 2 things:

    in your equation above you have FALSE,TRUE for the unique which will return only cases where the value is only found 1x but if you want all unique cases that TRUE should be FALSE or just left off

     

5 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    Variants

    formula

    =LET(
      data, GPO[about:config setting equivalent],
      fnSplit, LAMBDA(p,q, IF( SEQUENCE(q)=q, TEXTSPLIT( INDEX(data,q,),";"), p)),
      TOCOL( REDUCE("", SEQUENCE( ROWS(data) ),fnSplit ), 2)
    )

    OfficeScript

    function main(workbook: ExcelScript.Workbook) {
    
        const sheet = workbook.getActiveWorksheet()
        const rangeName: string = "GPO[about:config setting equivalent]"
        const data = [[rangeName]].concat(
            sheet.getRange(rangeName)
            .getValues()
            .map( x => x.toString().split(";"))
            .flat().map( x => [x] )
        )
        const target = sheet.getRange("H19")
            .getResizedRange(data.length - 1, 0)
    
            target.clear()    
            target.setValues(data)
    
            target.getCell(0,0).getFormat().getFill().setColor("green")
            target.getCell(0, 0).getFormat().getFont().setColor("white")
    }
  • I do not fully understand either the data or the required output but the attached file contains some helper functions that I published which address Microsoft's array of array shortcomings.

    = MAPĪ»(GPO[about:config setting equivalent],
        LAMBDA(element, TEXTSPLIT(element, ";"))
      )

    https://gist.github.com/pbartxl/a14b250985da31be843ce9ff35d888fc

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    if it is a small set you can get away with 

    =UNIQUE(TEXTSPLIT(TEXTJOIN(";",,GPO[about:config setting equivalent]),,";"))

    but I'm guessing that is not the case so you will probably need this:

    =UNIQUE(DROP(REDUCE("",GPO[about:config setting equivalent],LAMBDA(p,q,VSTACK(p,TEXTSPLIT(q,,";")))),1))

    that said I notice 2 things:

    in your equation above you have FALSE,TRUE for the unique which will return only cases where the value is only found 1x but if you want all unique cases that TRUE should be FALSE or just left off

     

    • dr-numbers's avatar
      dr-numbers
      Copper Contributor

      The table GPO is about 600 rows. I have worked through to understand what the first solution is doing and I'm guessing that "small" means it doesn't exceed the maximum length that a text string can be in Excel. I'm not sure how high that might be. I have tested that solution and it works.

      I haven't had chance to work through the second solution to understand what it is doing but I'm guessing with this "small" issue, it is worth doing.

      You are correct in regards to the TRUE in the UNIQUE formula. I want to keep one copy of the value no matter whether there is one copy in the original or more than one. Using the TRUE would be handy in going through contest entries where the contest rules only allow for one entry per person and multiple entries automatically void all entries for that person.

      • m_tarler's avatar
        m_tarler
        Bronze Contributor

        Yes that is correct, the "small" is in reference to the max string length allowed.

        To help you understand and work through the second here is a breakdown:

        =UNIQUE(
               DROP(
                   REDUCE("",GPO[about:config setting equivalent],
                        LAMBDA(p,q,
                                VSTACK(p,TEXTSPLIT(q,,";")))),1))

        so line 1 is the UNIQUE, which you already know

        line 2 is DROP which will drop any given number of elements of an array.  You can drop rows or columns or both and you can use negative numbers to drop from the end instead of the beginning.  In this case we are just dropping the 1st element to get rid of the "" initialization being used in the REDUCE

        line 3 is REDUCE which is a helper function to the LAMBDA in line 4.  REDUCE basically has an initial value and an array and will call the LAMBDA for each element in the array until the final answer is provided.  so simple example is initial value 0 and an array of expenses and then in LAMBDA you have a formula to add the tax rate for each expense so then each call of that LAMBDA will pass it a new expense value and that LAMBDA will return the prior value/sum with the new calculated tax on the newly passed expense added to it so in the end you get a sum of the tax on all the items.

        line 4 is LAMBDA which takes in some number of variables and then applies a formula to those variable and returns a value (much like a user defined function).  In this case it is used with the helper function REDUCE so it must have an accumulator (p) and a value (q).  In the tax sample I said above it might look like LAMBDA(p, q, p+0.07*q) so each call would have the accumulator (i.e. prior value returned from the LAMBDA) added to the newly passed value time 7%.

        line 5 is VSTACK of each TEXTSPLIT.  So I believe you understand the TEXTSPLIT and this line just stackes each row from the textsplit on top of each other.

        So the reason for the REDUCE - LAMBDA is that this will apply the TEXTSPLIT to each value individually and then build up a 'single' 2d table of the results.  There is major limitation with respect to array of arrays with LAMBDA functions but using REDUCE to return a 'single' table is a known 'work around' but since we initialized the REDUCE with "" the first row will be "" so we use DROP to get rid of that row.

        I recommend you continue to learn more about LAMBDA as it is extrememly useful and powerful.

        Finally w/r to UNIQUE and returning only cases where it occurs exactly 1 time, you gave an excellent application example but I wanted to mention another that I find it very useful.  If you have List A and you want to fill in List B using values from List A but not repeat any, then you can have a helper column tell you which unique values from List A are still left by using 

        =UNIQUE( VSTACK( ListA, ListB ), , 1)

        so then you can add Data Validation on the elements in List B and point that Data Valadation list to that helper column so they fill in only unique values from List A.

Resources