Would love to see a ListRemove() or similar to make it easier to remove an item from a list using a button. This issue has come up several times for me, where I want to do an operation like [list] - [thisRow]
Formula might be something like ListRemove([the list], [the item to remove]).
The solution within the topic you shared already uses Splice()
See the If() within the quote above
I’ll admit that the whole solution within that topic seems a bit complicated to read, because of all the nested WithName() (which are there to avoid some redundancy)… but I find it elegant .
Now, in a far less elegant way but maybe easier to grasp, here’s an action button also doing what was asked in the topic you shared … Which I’m just sharing trying to answer your question …
(You’ll find the sample below )
ModifyRows( //Click 1: Add the player
Games.Filter(Date = nextGame),
ModifyRows( //CLICK 2: Remove the player
Games.Filter(Date = nextGame),
Games.Filter(Date = nextGame).First().RSVPs.WithName(CurrentList,
In the “Click 2” action (the 2nd ModifyRows()) there’s this bit of formula :
It takes the table Games and look for the rows where CurrentValue.Date is equal to the nextGame (the date on the canvas).
This actually returns a list of 1 row from the table Games. So, to effectively get the row from that list of 1 row, I’ve appended First() to the Filter().
Now that we have the appropriate row, we can access the values in the field RSVPs. (I.e.: the list of players)
As I’m going to need that list in Splice() and to avoid repeating the Filter(), I’m storing the list within the named value CurrentList using WithName()
All that’s left to do is to Splice() the CurrentList according to the position of thisRow (which Find() helps us retrieve) within the CurrentList
CurrentList.Find(thisRow), //Start - (Where to begin to delete)
1 //deleteCount - How many to delete
Now, I’m not saying this doesn’t require a bit of work though … But I hope this helps
I think what @Andrew_Farnsworth means is a generic way to remove an element from a list — any list really — not by the item’s index in it but by the item itself. They mentioned [thisRow] because their desired use case is to make a button in a table that would remove the row it’s clicked in from a multi-selection lookup elsewhere (e.g. remove this task from a selection of tasks in a page control). Am I right?
Indeed, a formula to List.Remove(Item) would be a nice addition to the formula language.
Meanwhile you can do this in a few other ways:
MyList.Filter(CurrentValue != Item)
You may prefer the former when your list is short: the formula is short and easy to understand (only keep the items that are not the one).
The latter is gonna perform better when the list is longer but this will only work if the item is guaranteed to be in the list (e.g. the button becomes disabled when List.Contains(Item) != true). Otherwise you have to safeguard it like this:
The reason: if Item is not in the list, List.Find(Item) returns -1. But this is still a valid input for the Splice() formula — it means remove the 1st item from the list end. So instead of returning the unaffected list, the formula will remove the last item in case the item you want to remove is not found:
By Item I mean of course anything that could be in your list — including a number, thisRow, @-reference or whatever.
P.S. List.Add(Item) would also be a welcome formula. Yes, we can ListCombine() and Splice() already. But Splice() is too technical for an average user to understand, and ListCombine() unwraps the lists it’s given, which is sometimes unwanted.