Forum Discussion
Text Join - Return Unique Text Only
UNIQUE works with text fields in 365 but perhaps not in the manner you require.
Records are only eliminated only if they duplicate another record in its entirety.
I am not sure what you are planning to do with TEXTJOIN.
- journey4lifeOct 18, 2023Copper Contributor
In the example you share below for Dogs and Cats, I am trying to have an outcome of what pet types and what colors they are available in - both unique values based on the data in the 'original table'
Dog Black, BrownCat Ginger, Black, White
- PeterBartholomew1Oct 19, 2023Silver Contributor
This is the file. I have made life more complicated by including a version that returns the colours as an array of arrays, as opposed to an array of comma-separated lists.
- PeterBartholomew1Oct 19, 2023Silver Contributor
I would normally recommend a new question but, since the test data already exists, I will try to answer here. What you require is an array of comma-separated lists which is supported in Excel 365, if a little complicated. In the example, the first task of creating an array of distinct species is straightforward.
= LET( species, UNIQUE(Pet), species )To continue the formula to colours can be achieved by defining a Lambda function that returns the list of colours for a single species.
= LAMBDA(s, LET( distinctColour, UNIQUE(FILTER(Colour, Pet = s)), TEXTJOIN(", ", , distinctColour) ) )To test the function
= SpeciesColoursλ("Dog") returns "Black, Brown"This allows the initial formula to be extended using MAP and the new Lambda function
= LET( species, UNIQUE(Pet), colours, MAP(species, SpeciesColoursλ), HSTACK(species, colours) )Things get harder if the lists are expected to be returned as row arrays giving a ragged 2D array!