Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Replace values in bulk

Dear All  ImkeF  - if you can please look into this query 🙂   there is a Administrative Code Master (Lookup table) which is loaded into Main Master Data table in Power Query.  Administrative Codes...
  • smpa01's avatar
    5 years ago

    Anonymous  what you can do here is

    let's suppose this is you new value table

    //tablename newval
    
    let
        Source = Web.BrowserContents("https://community.powerbi.com/t5/Power-Query/Replace-values-in-bulk/m-p/1629873#M49960"),
        #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(5) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(5) > * > TR > :nth-child(2)"}, {"Column3", "TABLE:nth-child(5) > * > TR > :nth-child(3)"}, {"Column4", "TABLE:nth-child(5) > * > TR > :nth-child(4)"}, {"Column5", "TABLE:nth-child(5) > * > TR > :nth-child(5)"}}, [RowSelector="TABLE:nth-child(5) > * > TR"]),
        #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Cost Code", type text}, {"Discipline", type text}, {"Sub Discipline", type text}, {"Location", type text}, {"Function", type text}})
    in
        #"Changed Type1"

     once you append the new val to masterdata and follow the steps. In this way you can always ensure that the up-to-date values are reflected for each code

    //tbl masterdata
    
    let
        Source = Web.BrowserContents("https://community.powerbi.com/t5/Power-Query/Replace-values-in-bulk/m-p/1629873#M49960"),
        #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(2) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(2) > * > TR > :nth-child(2)"}, {"Column3", "TABLE:nth-child(2) > * > TR > :nth-child(3)"}, {"Column4", "TABLE:nth-child(2) > * > TR > :nth-child(4)"}, {"Column5", "TABLE:nth-child(2) > * > TR > :nth-child(5)"}}, [RowSelector="TABLE:nth-child(2) > * > TR"]),
        #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Appended Query" = Table.Combine({#"Promoted Headers", newval}),
        #"Grouped Rows" = Table.Group(#"Appended Query", {"Cost Code"}, {{"ad", each _, type table [Cost Code=nullable text, Discipline=nullable text, Sub Discipline=nullable text, Location=nullable text, Function=nullable text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let x = [ad], y = Table.AddIndexColumn(x, "Index", 1, 1, Int64.Type), z = Table.SelectRows(y, each [Index] = List.Max(y[Index])) in z),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Cost Code", "Discipline", "Sub Discipline", "Location", "Function", "Index"}, {"Cost Code", "Discipline", "Sub Discipline", "Location", "Function", "Index"})
    in
        #"Expanded Custom"