Forum Discussion
Anonymous
4 years agoNot applicable
Subtract values from same column but based on value from another column in Query Editor
I want to get "Output Column" based on following condition in Power Query (M language): if column1 value is "Peter" then "Output Column" would be value of (Peter - Fab- Kris) else value from colum...
- 4 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtSS1S0lEyNDA1UIrViVZySSxLBfENIVzHnEwgz9QMzHFLTAJyLE3BHO+izGIgzxzIiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Output", each if [Column1]="Peter" then [Column2] -Table.SelectRows(#"Changed Type",each [Column1]="Fab"){0}[Column2] -Table.SelectRows(#"Changed Type",each [Column1]="Kris"){0}[Column2] else [Column2]) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
lbendlin
4 years agoSuper User
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtSS1S0lEyNDA1UIrViVZySSxLBfENIVzHnEwgz9QMzHFLTAJyLE3BHO+izGIgzxzIiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Output", each
if [Column1]="Peter" then [Column2]
-Table.SelectRows(#"Changed Type",each [Column1]="Fab"){0}[Column2]
-Table.SelectRows(#"Changed Type",each [Column1]="Kris"){0}[Column2]
else [Column2])
in
#"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".