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 are 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 the approach more granular and iterate over each row using FormulaMap(). Then you can get the Score value for each row and increment it accordingly

2 Likes

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):

Has there been any progress on solving this (having access to thisRow or currentValue in ModifyRows)? I’m running up against this when trying to create an automation that applies a formula based on another column’s value.

While I agree that I wish that ModifyRows supported currentValue, I found a solution for my use-case (using ModifyRows in an automation where the final value is dependent on another column in the same row):

I created a new button column and added the transformation as the button action.

Then I updated the automation to:

  1. filter for all of the rows that I want modified,
  2. then apply a FormulaMap to that set of rows that pushes the button
Rows
  .Filter(criteria)
  .FormulaMap(
      RunActions(CurrentValue.TargetButton)
  )

This allows me to filter which buttons I want pressed without encountering an error (if you run an automation on a column with disabled buttons, for some reason it throws an error – you’d think it’d be smart enough to ignore disabled buttons).

Hi @MrChrisRodriguez,

I think the solution eventually arrived thanks to the WithName() formula recently launched:

So, finally no more workaround to access directly different level of nested cycles.
However, let me know should you think your use-case cannot be solved with WithName().

Cheers!

Hi @Federico_Stefanato, please correct me if I’m wrong, but I don’t think it does. ModifyRows doesn’t expose thisRow or currentValue so withName doesn’t help.

Hi @MrChrisRodriguez ,

Mumble… I’m a bit puzzled so maybe I’m not understanding properly.

For instance (no nested loops):

Table.FormulaMap(
  CurrentValue.ModifyRows(ColumnName, CurrentValue.ColumnName+1)
)

It does work.

What you can’t do within your loop?

Thanks.

I haven’t tested it, but I think you’re right. I’m going to give it a look-over later. Thanks for the help.