Forum Discussion

nbcholst's avatar
nbcholst
Frequent Visitor
8 years ago
Solved

Is it possible to create a table based on combining two columns

Hi All,   I have a table that has a list of Items - A,B,C, etc.   I also have a table that has a value matched to each item. So A = 3, B = 4, C = 2, etc.   I want to create a table of unique Le...
  • Ashish_Mathur's avatar
    8 years ago

    Hi,

     

    You only need one table to solve this problem - the second one.  You will have to use the following M code in Power Query

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Items", type text}, {"Repeat till", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Start from", each 1),
        #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Items", "Start from", "Repeat till"}),
        #"Added Custom1" = Table.AddColumn(#"Reordered Columns", "Custom", each { Number.From([Start from])..Number.From([Repeat till]) }),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start from", "Repeat till"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Custom", type text}}),
        #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.1", each [Items]&[Custom]),
        #"Renamed Columns" = Table.RenameColumns(#"Added Custom2",{{"Custom.1", "Result"}}),
        #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"Items", "Custom"})
    in
        #"Removed Columns1"