Forum Discussion
Mark rows depending on previous row
- 6 years ago
Hello Anonymous
you can add a group-function and then with a Table.TransformColumns apply the necessary changes to the table.
Here the complete solution
let Source = #table ( {"A","B"}, { {"1","0"}, {"1","0"}, {"1","1"}, {"1","0"}, {"1","0"}, {"1","0"}, {"2","1"}, {"2","0"}, {"2","0"}, {"3","0"}, {"3","0"}, {"3","0"}, {"3","0"}, {"3","1"}, {"3","0"} } ), Group = Table.Group(Source, {"A"}, {{"AllRowsB", each Table.SelectColumns(_, "B"), type table [A=text, B=text]}}), AddColumn = Table.TransformColumns ( Group, { { "AllRowsB", each Table.ReplaceValue(Table.FillDown( Table.AddColumn(_,"C",(row)=> if row[B] = "1" then "2" else null), {"C"}), null, "0", Replacer.ReplaceValue, {"C"}) } } ), ExpandedAllRowsB = Table.ExpandTableColumn(AddColumn, "AllRowsB", {"B", "C"}, {"B", "C"}) in ExpandedAllRowsBCopy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello Anonymous
you can add a group-function and then with a Table.TransformColumns apply the necessary changes to the table.
Here the complete solution
let
Source = #table
(
{"A","B"},
{
{"1","0"}, {"1","0"}, {"1","1"}, {"1","0"}, {"1","0"}, {"1","0"}, {"2","1"}, {"2","0"}, {"2","0"}, {"3","0"}, {"3","0"}, {"3","0"}, {"3","0"}, {"3","1"},
{"3","0"}
}
),
Group = Table.Group(Source, {"A"}, {{"AllRowsB", each Table.SelectColumns(_, "B"), type table [A=text, B=text]}}),
AddColumn = Table.TransformColumns
(
Group,
{
{
"AllRowsB",
each Table.ReplaceValue(Table.FillDown( Table.AddColumn(_,"C",(row)=> if row[B] = "1" then "2" else null), {"C"}), null, "0", Replacer.ReplaceValue, {"C"})
}
}
),
ExpandedAllRowsB = Table.ExpandTableColumn(AddColumn, "AllRowsB", {"B", "C"}, {"B", "C"})
in
ExpandedAllRowsB
Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy