ModifyRows should allow CurrentValue to modify rows with different values

Currently, ModifyRows does not set CurrentValue to each row as it goes by. This is unfortunate, because if I want to make, say, a button that adds 1 to every value in a column, I want to put something in this box:

image

Say:

image

But clicking this button does not do anything like what is expected. Score finds the entire column, so Score+1 is, apparently, [...]1, where ... are the values of the column. Trying to do it with CurrentValue explicitly doesn’t work:

image

image

I don’t even know what CurrentValue is here, but it’s apparently not the row.

ModifyRows should set CurrentValue to each row that it is modifying.

I don’t know if you just reporting the problem or still trying to find a solution. In case you want to achieve something like, you can use formula map like this

The idea is to make approach more granular and iterate over each row using FormulaMap(). Then you can get the Score value for each row and increment it accordingly

1 Like

I made this thread specifically to suggest this improvement to ModifyRows. I did try your workaround, which I found on another thread here, but it is buggy and doesn’t work. See "Exception occured" trying to update row

I have another workaround, though, so all is not lost.

I’ve been using this workaround a lot on other tables, using FormulaMap and then ModifyRows(CurrentValue, ...), and I’ve discovered something else about it: each ModifyRows creates a separate Undo queue, so undoing transformations on a large dataset takes a while and it’s difficult to find your way back to the original change. This is definitely less than ideal!

(It might be nice, separately, to be able to group actions together to run atomically for the purposes of Undo, but that’s a different request!)

Hi @Alexis_Hunt,

I’m sorry I didn’t see this one earlier with your mention CurrentValue. From your first post, if you want to single out an individual row’s value for a column, you can use thisRow.

So in your case in the first post, thisRow.Score + 1 would give you the score for that row plus 1 instead of the total score for that row.

Hey @BenLee, sorry but there’s no thisRow in the context of a canvas button (I just had to check it myself because that’s what I believed but your post made me doubt that).

@Jaisil_Muttakulath_Joy is correct, the proper way to perform the change individually on each row is to use Table.FormulaMap(CurrentValue.ModifyRows(...)). The mass-ModifyRows on multiple rows at once is only possible if you want to set the same value (evaluated once) on all rows, not individually calculated value per row. That’s why there’s no CurrentValue in that context.

And yeah. spamming the undo queue is a known issue. One of the reasons I don’t depend on undo at all, and just prefer to hide that alert altogether. If needed, I’d rather make my own button to “undo” the change.

A somewhat related request: Add an action to show custom alert (dark popup in the bottom)

2 Likes

I missed that it was a canvas button.

Thank you for pointing that out!

1 Like

I ran across another case where I actually did use CurrentValue inside of ModifyRows to refer to something outside of the row being modified, so just making this change straight-up would break that code and not give it a good way to fix it.

I guess, then, the only way to address this in a fully general way would be to add proper first-class functions, in which case ModifyRows could accept a function in place of a new row, in order to generate a new row to update with.

The CurrentValue context issue is a known and perhaps the most discussed one:

Usually there are ways to work around this. E.g. if you need to iterate over X rows and perform some action in each of them, and you both need the CurrentValue as in the I-th row, and CurrentValue as within that operation (e.g. a filter within), you’d most likely just want to add a button column. The outer CurrentValue would then be replaced with thisRow, and you can make a button that would click all the buttons in the column.

For trickier situations the bulletproof solution is this (the tutorial desperately needs updating though):