Forum Discussion

threw001's avatar
threw001
Helper III
2 years ago
Solved

Manipulate table column / row with same ID

Hi guys,   I have the below Table A where the ID's are repeated based on the field 'Question Name'. For example Form ID A001 and A002 are repeated 5 times due to 5 questions being answered in the f...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi threw001 

    Based on the solution lbendlin  provided, You can try the following code.

     

    let
        Source = Excel.Workbook(File.Contents("C:\Users\Me\OneDrive -Me\Documents\SampleDataSetMultipleIDs.xlsx"), null, true),
     Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Form ID", type text}, {"Client ID", Int64.Type}, {"Question Name", type text}, {"Question Answer", type text}, {"Form Submitted Date", type date}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Question Name] <> "Country")),
        #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[#"Question Name"]), "Question Name", "Question Answer")
    in
        #"Pivoted Column"

     

    If the solution helped, please consider to mark this way and the way  lbendlin  offered as a solution.

     

    Best Regards!

    Yolo Zhu

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

  • lbendlin's avatar
    lbendlin
    2 years ago
    let
       Source = Excel.Workbook(File.Contents("C:\Users\Me\OneDrive -Me\Documents\SampleDataSetMultipleIDs.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Pivoted Column" = Table.Pivot(Sheet1_Sheet, List.Distinct(Source[#"Question Name"]), "Question Name", "Question Answer")
    in
        #"Pivoted Column"

     

    This is still missing the Promoted Headers stage but you get the point.  Power Query steps usually reference a prior step.