Forum Discussion

toum's avatar
toum
Helper II
2 years ago
Solved

Power Query calculated column

Hello all, please, I need your help with Power Query. I need to create a new column that follows this logic:    
  • tackytechtom's avatar
    tackytechtom
    2 years ago

    Hi toum ,

     

    Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

     

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQKhWJ1oJScgwxGMQTxnIMsJJuWCzHFDUecBZLnBpIKBjCAwBvG8gaxgsFQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Home = _t, Destination = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Home", type text}, {"Destination", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Home"}, #"Changed Type", {"Name"}, "Added Custom", JoinKind.LeftOuter),
    #"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Destination"}, {"Added Custom.Destination"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Added Custom2", "NewColumn", each
    if [Destination] = "" then [Added Custom.Destination]
    else [Destination]),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom",null, each [Name],Replacer.ReplaceValue,{"NewColumn"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Added Custom.Destination"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Name", Order.Ascending}})
    in
    #"Sorted Rows"

     

    Do not forget to mark the answer as a solution so others can easily spot the answer!

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/