Forum Discussion

wjeanes's avatar
wjeanes
Icon for Advocate III rankAdvocate III
4 years ago
Solved

Update a blank row if two rows in another column match

Not sure if this is the right place to get help on something like this but here goes.

 

This seems so simple yet I'm completely stuck.  Essentially all I want to do is populate the custom Column "Fixed Code" with the value in JobCode wherever the Reference column matches.

 

This needs to be done in Powery Query though not as a calculated column in Dax as only the A rows would be used throughout the datamodel and B rows would be filtered out after the custom column has been populated.

 

Item codeABReferenceJobCodeFixedCode
1000100AABC123 17PTH
MCA001BABC12317PTH17PTH
  • Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  The key is to replace your blanks with nulls to get the fill down to work.  Your sample data had a space, but adapt the Replaced Value step for your actual data.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMABiJR0lRxB2cjY0MgYyFJRidaKVfJ0dgbJArhOynKF5QIiHUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Item code" = _t, AB = _t, Reference = _t, JobCode = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item code", type text}, {"AB", type text}, {"Reference", type text}, {"JobCode", type text}}),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type"," ",null,Replacer.ReplaceValue,{"JobCode"}),
        #"Sorted Rows" = Table.Sort(#"Replaced Value",{{"JobCode", Order.Descending}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Sorted Rows", "JobCode", "Fixed Code"),
        #"Filled Down" = Table.FillDown(#"Duplicated Column",{"Fixed Code"})
    in
        #"Filled Down"

     

    Pat

1 Reply

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  The key is to replace your blanks with nulls to get the fill down to work.  Your sample data had a space, but adapt the Replaced Value step for your actual data.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMABiJR0lRxB2cjY0MgYyFJRidaKVfJ0dgbJArhOynKF5QIiHUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Item code" = _t, AB = _t, Reference = _t, JobCode = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item code", type text}, {"AB", type text}, {"Reference", type text}, {"JobCode", type text}}),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type"," ",null,Replacer.ReplaceValue,{"JobCode"}),
        #"Sorted Rows" = Table.Sort(#"Replaced Value",{{"JobCode", Order.Descending}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Sorted Rows", "JobCode", "Fixed Code"),
        #"Filled Down" = Table.FillDown(#"Duplicated Column",{"Fixed Code"})
    in
        #"Filled Down"

     

    Pat