Forum Discussion

ryan1919's avatar
ryan1919
Frequent Visitor
3 years ago
Solved

How to insert dynamic and unique "null" value

PBIC, I am having trouble thinking of how to write Power Query to transform a column.   I have shown a sample table below. The left column is "Unique Property Full Address (before)".  This is dat...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ryan1919 ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) Find "Advanced Editor" in the power query and open it, copy and paste the following code. You can check the steps in the step bar on the right and click on the gear to see the details of a step.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxJKUotLlYwVIrVQfCMwDwFJBImY4zCM0HhmeLUZQYTiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Unique Property Full Address" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unique Property Full Address", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Unique Property Full Address] =" " then 1 else 0),
        #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type),
        #"Added Custom1" = Table.AddColumn(#"Added Index", "Custom.1", each List.Sum(List.FirstN(#"Added Custom"[Custom],[Index]))),
        #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom.1", type text}}),
        #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.2", each if [Unique Property Full Address] = " " then "null"&[Custom.1] else [Unique Property Full Address]),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Unique Property Full Address", "Custom", "Index", "Custom.1"})
    in
        #"Removed Columns"

    (3) Then the result is as follows.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.