I have something for problem 2 but I might have overcomplicated the thing (I got lost somewhere I think … or I’m simply a bit too tired )
I think I’m just not sure why you need to recreate a list using 2 columns when for the updated list of rows the value seem to be the same as the value within Column 1 …
I mean, for the example in the Problem 2 page, Column 1 is already what’s expected in Column 2 …
But lol, I re-created the list anyway … It’s just a thought I had …
So the first thing I did was to add a column to store the position of the each row in Column 2
and each row in the column Rows to add to column 2
relative to Column 1
(as they are supposed to follow that order) … That new column is called Position Column 2 + Row to add (relative to Column 1)
( )
Action 1 : “Add” the rows to Column 2
ModifyRows(
thisRow,
thisRow.[Result - Column 2],
ListCombine(
thisRow.[Column 2].Split("/"),
thisRow.[Rows to add to column 2].Split("/")
).WithName(
C,
Sequence(1, C.Count()).ForEach(
C.Nth(thisRow.[Position Column 2 + Row to add (relative to Column 1)].Nth(CurrentValue
)
)
)
).Join("/")
)
So, I ListCombine()
the 2 field to somewhat “merge” and I give to that list the name C
using WithName()
and then in the expression part of WithName()
we have this :
Sequence(1, C.Count()).ForEach(
C.Nth(thisRow.[Position Column 2 + Row to add (relative to Column 1)].Nth(CurrentValue)
)
)
And what this does is : it first create a Sequence()
(i.e.: a list) going from 1 to count of values in C
(each value being stored as CurrentValue
) and for each value in that sequence it will return the Nth()
value in C
with the appropriate position relative to Column 1
I’m sorry, I have no idea how to explain this clearly at the moment …
But if I take your example and the very first CurrentValue
in that ForEach()
with the list in Position Column 2 + Row to add (relative to Column 1)
being 1,3,2,4
Let’s say CurrentValue
= 1
→ C.Nth([Position relative to Column 1].Nth(1))
and as [Position relative to Column 1].Nth(1)
is 1
the result of that 1st iteration is the first value in C
→ r1
.
For CurrentValue
= 2
→ C.Nth([Position relative to Column 1].Nth(2))
→ [Position relative to Column 1].Nth(2)
= 3
→ C.Nth(3)
→ r444
Etc… (Sorry, I really can’t do better right now )
As for Action 2, it follows the same principle but for the position this time
ModifyRows(
thisRow,
thisRow.[Result - Column 3],
ListCombine(
thisRow.[Column 3].Split("/"),
thisRow.[Rows to add to column 2].Split("/").ForEach(CurrentValue.RegexReplace("r\d+", "p0"))
).WithName(D,
Sequence(1,D.Count()).ForEach(
D.Nth(thisRow.[Position Column 2 + Row to add (relative to Column 1)].Nth(CurrentValue))
)
).Join("/")
)
Once again, this might need some adjustments … But I hope it helps a little !
Edit: As the field Position Column 2 + Row to add (relative to Column 1)
uses both Column 2
and Rows to add to column 2
as they are and the list is used in both buttons, this field would need to stay as it it until both rows and positions are fully updated …