Forum Discussion
josephrandall
3 years agoRegular Visitor
Remove row with incorrect value
See picture below. There is one row (highlighted) that the value is wrong. Is there anyway I can remove this row via formula? Basically if the values of the row above and below are equal to each oth...
- 3 years ago
Here is a function you can use to add the next and previous row values as columns to your table.
You would invoke it like:
Table_Window(MyQuery, {-1, 1}, {"id})
This will add "id-1" and "id+1" columns
// Table_Window let fn = (table as table, offsets as anynonnull, columns as anynonnull) => let columns = if not (columns is list) then {columns} else columns in let indexColumnName = Text.NewGuid() in let table = Table.AddIndexColumn(table, indexColumnName, 0) in let withIndexFn = (table as table, offset as anynonnull) => if offset = {} then table else if offset is list then @withIndexFn(@withIndexFn(table, offset{0}), List.Skip(offset)) else let indexColumnName2 = Text.NewGuid() in let table2 = Table.SelectColumns(table, columns) in let table2 = Table.AddIndexColumn(table2, indexColumnName2, -offset) in let newColumnNames = List.Transform(columns, each _ & (if offset > 0 then "+" else "") & Number.ToText(offset)) in let table2 = Table.RenameColumns(table2, List.Zip({columns, newColumnNames})) in let joinedTable = Table.Join(table, {indexColumnName}, table2, {indexColumnName2}, JoinKind.LeftOuter) in let joinedTable = Table.RemoveColumns(joinedTable, {indexColumnName2}) in let joinedTable = Table.Sort(joinedTable, indexColumnName) in joinedTable in let table = withIndexFn(table, offsets) in let table = Table.RemoveColumns(table, {indexColumnName}) in table in fn
artemus
3 years agoMicrosoft Employee
Here is a function you can use to add the next and previous row values as columns to your table.
You would invoke it like:
Table_Window(MyQuery, {-1, 1}, {"id})
This will add "id-1" and "id+1" columns
// Table_Window
let fn = (table as table, offsets as anynonnull, columns as anynonnull) =>
let columns = if not (columns is list) then {columns} else columns in
let indexColumnName = Text.NewGuid() in
let table = Table.AddIndexColumn(table, indexColumnName, 0) in
let withIndexFn = (table as table, offset as anynonnull) =>
if offset = {} then
table
else if offset is list then
@withIndexFn(@withIndexFn(table, offset{0}), List.Skip(offset))
else
let indexColumnName2 = Text.NewGuid() in
let table2 = Table.SelectColumns(table, columns) in
let table2 = Table.AddIndexColumn(table2, indexColumnName2, -offset) in
let newColumnNames = List.Transform(columns, each _ & (if offset > 0 then "+" else "") & Number.ToText(offset)) in
let table2 = Table.RenameColumns(table2, List.Zip({columns, newColumnNames})) in
let joinedTable = Table.Join(table, {indexColumnName}, table2, {indexColumnName2}, JoinKind.LeftOuter) in
let joinedTable = Table.RemoveColumns(joinedTable, {indexColumnName2}) in
let joinedTable = Table.Sort(joinedTable, indexColumnName) in
joinedTable
in
let table = withIndexFn(table, offsets) in
let table = Table.RemoveColumns(table, {indexColumnName}) in
table
in
fn
josephrandall
3 years agoRegular Visitor
thank you, kindly.