How do I remove an item from a list?

How do I remove an item from a list? For example, lets say I have a list {2,4,4,1,9,3}. How can I remove only one of the 4’s from the list? Or, how could I remove item #3 from the list? I can’t use list subtraction because it removes both 4’s from the list.

Steve

0 10 1,351
10 REPLIES 10

Both the examples you have shared are related to the number 4 in the list that appears twice in the list. So could you update if you are trying to remove an item at a specific position in a list or are you trying to remove duplicates from the list?

If you wish all the duplicates removed from a list, please use UNIQUE() function.

If you wish to remove an item at a specific position( index) from a list , you could construct an expression with the INDEX() function.

Please post back if you are looking for something else.

Thanks for the quick reply! I know the index of the item I want to delete from the list. So what would be the the formula to return the list with that item removed?

With index used, if the item is duplicate, the order of the remaining item in the list will be disturbed. Meaning if list is {2,4,4,1,9,3} and 4 at position 3 needs to be removed, the result will look like {2,1,9,3, 4}

Will it do?

Yes, that would be fine. I am going to sort the list after the item is removed anyway.

Sorry that I did not ask a question earlier. Is you main intention to remove duplicates or a single element at some known index position. And if there are duplicates , how many times a duplicate can occur> Is it only twice or more than that?

Could be more than that.

Thank you. I( believe there is no trivial way to achieve what you are looking for. If I come across a solution, I will post.

Ok. Thanks Suvrutt!

Have tried to put an expression together, a bit longish. It could be possibly further optimized, but the following works even with lists having duplicates per my basic testing. Please test well.

IF(LEN(TEXT([NumberList V]))-(LEN(TEXT(TOP([NumberList V], [IndexPosition])))+2)<0,TOP ([NumberList], [IndexPosition]-1),
TOP ([NumberList], [IndexPosition]-1) + SPLIT(RIGHT([NUMBERLIST V] , LEN(TEXT([NumberList V]))-(LEN(TEXT(TOP([NumberList V], [IndexPosition])))+2)),","))

In the above expression [IndexPosition] is Number Type column. Denotes the position of the number that needs to be removed from the list.
[NumberList] is a column type enumlist with base type as number. Something like {2,4,4,1,9,3}. that you have shared. [NumberList] is presumed to create a list in the AppSheet standard format , meaning {1, 2 , 3 , 4 , 5} -There is a space between number and next and previous commas.

The expression removes a number or item from the [NumberList] column at the position denoted by [IndexPosition]

Edit: Expression changed to take care of some edge conditions.

Thanks! I will try it out and work with it.

Top Labels in this Space