Forum Discussion

Babycakes_00's avatar
Babycakes_00
Helper I
1 year ago
Solved

Pivot or Group

Hi all I have a data set that I need to Change the structure and format

 

Any suggestions to reformat this data?

 

Desired Outcome is

FORM IDDate outDateInReceivalNoIDNameLocationTestSizeComment
12311/26/2024 00:00:009/11/2024 0:009999991LisaActionTest  
12411/27/2024 00:00:0011/27/2024 00:00:00156338Not SetJohnActionTestSmall 
12511/27/2024 00:00:0011/27/2024 00:00:00156338Not SetBillActionTestSmall 

 

Current Format is

FORM IDEntryIDNameValue
1233486Date out11/26/2024 00:00:00
1233487DateIn9/11/2024 0:00
1233488ReceivalNo999999
1233489ID1
1233490NameLisa
1233491LocationAction
1233492TestTest
1233493Size 
1233494Comment 
1243606Date out11/27/2024 00:00:00
1243607DateIn11/27/2024 00:00:00
1243608ReceivalNo156338
1243609IDNot Set
1243610NameJohn
1243611LocationAction
1243612TestTest
1243613SizeSmall
1243614Comment 
1251552Date out11/27/2024 00:00:00
1251553DateIn11/27/2024 00:00:00
1251554ReceivalNo156338
1251555IDNot Set
1251556NameBill
1251557LocationAction
1251558TestTest
1251559SizeSmall
  • Hello Babycakes_00 

     

    In Power Query you can follow this simple steps to get the table stucture you want.

    1. Select the FORM ID and Name columns.
    2. Go to the Transform tab and click on Pivot Column.
    3. Use Value as the "Values Column."

    If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN 

4 Replies

  • tackytechtom's avatar
    tackytechtom
    Most Valuable Professional

    Hi Babycakes_00 ,

     

    How about this? 🙂

     

    Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9b4MwEIb/CmKOhD/AQLe2WRJFDKFblMFClmoJ8BC3Q399z9Yl5YRFg5De072PDH4ul5wLme9yWTYKYq+9ydyXh5HzQqhCMFFmjL3EN7/uFnyN/GGGoS0CH+EV2ECczWDstx47F+D4UKiFOOzDd8m+ZRCdngzEyd40LXnYukF768JPvA5xIIiA+DA3fw9ShujtTzg8o00J8e6mycx+UYatVCxhqk6aQp6Y+pde6eKVkrKh0ENX53zWG09avpB2dJ8zLbekIZKWhuVCWj/pcaRtWlwVr1GJZ8UhL58Th3S5KQ6hKi0OW/Un7s0+roZlvSEOkSYpDst2Je76Cw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"FORM ID" = _t, EntryID = _t, Name = _t, Value = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"FORM ID", Int64.Type}, {"EntryID", Int64.Type}, {"Name", type text}, {"Value", type text}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"EntryID"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Name]), "Name", "Value")
    in
        #"Pivoted Column"

     

    Let me know if this helps 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/

  • Chewdata's avatar
    Chewdata
    Responsive Resident

    Hey!

    This can be achieved by using the pivot function in Power query. 
    To achieve this, first remove the column that makes every row unique ( [ EntryID]). 
    Secondly use Table.Pivot on the name and value columns. Selecting Don't aggregate in the advanced options.


    Codesnippet:

    let
        Source = YOURTABLE,
        #"Removed Columns" = Table.RemoveColumns(Source,{"EntryID"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Name]), "Name", "Value")
    in
        #"Pivoted Column"


     

  • dharmendars007's avatar
    dharmendars007
    Memorable Member

    Hello Babycakes_00 

     

    In Power Query you can follow this simple steps to get the table stucture you want.

    1. Select the FORM ID and Name columns.
    2. Go to the Transform tab and click on Pivot Column.
    3. Use Value as the "Values Column."

    If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Babycakes_00 

    Dod the solutions dharmendars007 , Chewdata  and tackytechtom  offered help you solve the problem, if them help, you can consider to accept them as solutions so that more user can refer to, or if you have other problems, you can offer some information so that can provide more suggestion for you.

     

    Best Regards!

    Yolo Zhu