Forum Discussion
bc2022
3 years agoFrequent Visitor
How to update a cell value based on the conditional result of another column
I come across a situation which I need to update the cell value with the correspondent value of other column based on the conditions. Here is an exmple: code category value aba a ...
- 3 years ago
Hi bc2022 ,
you can do it without additional merging like so:let Source = Table.Buffer( Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "i45WSkxKVNJRAmFDpVgdED8FyE4FYiMoPxnIBmFTKD8VjQ9ig/QYQ/lpQHYSECsoxcYCAA==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [code = _t, category = _t, value = _t] )), #"Replaced Value" = Table.ReplaceValue( Source, each [value], each if [code] = "abf" then Table.SelectRows(Source, (x) => x[category] = "c"){0}[value] else [value], Replacer.ReplaceValue, {"value"} ), #"Changed Type" = Table.TransformColumnTypes( #"Replaced Value", {{"code", type text}, {"category", type text}, {"value", Int64.Type}} ) in #"Changed Type"For performance reasons, buffering the Source-table is strongly recommended, as it will be referenced in each row of the new table during the replacement operation.
ImkeF
3 years agoCommunity Champion
Hi bc2022 ,
you can do it without additional merging like so:
let
Source = Table.Buffer( Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WSkxKVNJRAmFDpVgdED8FyE4FYiMoPxnIBmFTKD8VjQ9ig/QYQ/lpQHYSECsoxcYCAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [code = _t, category = _t, value = _t]
)),
#"Replaced Value" = Table.ReplaceValue(
Source,
each [value],
each
if [code] = "abf" then
Table.SelectRows(Source, (x) => x[category] = "c"){0}[value]
else
[value],
Replacer.ReplaceValue,
{"value"}
),
#"Changed Type" = Table.TransformColumnTypes(
#"Replaced Value",
{{"code", type text}, {"category", type text}, {"value", Int64.Type}}
)
in
#"Changed Type"
For performance reasons, buffering the Source-table is strongly recommended, as it will be referenced in each row of the new table during the replacement operation.