Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Tabular Format to List Field Value

Hi Team,

 

I have table data in below format 

FieldNameValue
FirstNameAtul
LastNameKumar
Age28
DesignationProgrammer
FirstNameTony
LastNameM
Age32
DesignationTeam Lead
FirstNameKen
LastNameT
Age40
DesignationSME, PM

 

And I want to conver this to proper tabular format as below :

FirstNameLastNameAgeDesignation
AtulKumar28Programmer
TonyM32Team Lead
KenT40SME, PM

 

Some field value may have Comma in between.

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Pat,

     

    Thanks for your time and reply. Appreciate your time. I got the desinred result using simple Table.FromRows function.

     

    = Table.FromRows( List.Split(MyData[Field_Value], 4) )

    = Table.RenameColumns(Source,{{"Column1", "FirstName"}, {"Column2", "LastName"}, {"Column3", "Age"}, {"Column4", "Designation"}})

     

    MyData is the table name and there were 4 repated colum values in Vertical table. 

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Please see the example M code below for one way to transform your example data.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsssKi7xS8xNVdJRciwpzVGK1YlW8kmEi3mX5iYWgQUd00F8IwswxyW1ODM9L7EkMz8PKBhQlJ9elJibmwpRiWxmSH5eJbqZvkjmGRthMS8kNTFXwSc1MQXDOO/UPHTTQpBMMzHAYlqwr6uOQgDQ0lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FieldName = _t, Value = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"FieldName", type text}, {"Value", type text}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
        #"Added Custom" = Table.AddColumn(#"Added Index", "ItemNumber", each Number.RoundUp([Index]/4,0)),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[FieldName]), "FieldName", "Value"),
        #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"ItemNumber"})
    in
        #"Removed Columns1"

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Pat,

     

    Thanks for your time and reply. Appreciate your time. I got the desinred result using simple Table.FromRows function.

     

    = Table.FromRows( List.Split(MyData[Field_Value], 4) )

    = Table.RenameColumns(Source,{{"Column1", "FirstName"}, {"Column2", "LastName"}, {"Column3", "Age"}, {"Column4", "Designation"}})

     

    MyData is the table name and there were 4 repated colum values in Vertical table.