Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Mapping a value based on list sequence

Hello all,    I'm sorry if the subject is not clear, but I'll try to explain it here.   So, I have data containing branch city and function type every time a package gets scanned IN through logis...
  • v-jingzhang's avatar
    3 years ago

    Hi Anonymous 

     

    Here is my solution. Hope it helps. 

    let
        Source = data,
        #"Added Custom" = Table.AddColumn(Source, "RouteSplit", each Text.Split([Route], "/")),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Types", each List.Transform([RouteSplit], each Text.BeforeDelimiter(_, "_"))),
        #"Added Custom2" = Table.AddColumn(#"Added Custom1", "New Types", each 
            if List.Contains([Types], "GR.A FM") 
            then List.Transform([Types], each if _ = "GR" then "GR LM" else _) 
            else 
                let 
                    _firstGR = List.PositionOf([Types], "GR") 
                in 
                    if _firstGR = -1 
                    then [Types] 
                    else List.ReplaceValue(List.ReplaceRange([Types], _firstGR, 1, {"GR FM"}), "GR", "GR LM", Replacer.ReplaceValue)),
        #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Route Mapped", each Text.Combine(List.Transform(List.Zip({[New Types],List.Transform([RouteSplit], each Text.AfterDelimiter(_, "_"))}), each Text.Combine(_, "_")), "/")),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom3",{"Index", "Route", "Route Mapped"})
    in
        #"Removed Other Columns"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

    mapping based on sequence in a list - Copy.xlsx26 KB