Share via

automate Excel data structure/view

miguelalger 80 Reputation points
2025-11-26T15:04:57.5+00:00

I have a simple list -

column A - "Project code" - "ABC", "XYZ

column B - "Job #"

how can I automate the organization of this data like the following?

ABC XYZ
01 11
02 12
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

4 answers

Sort by: Most helpful
  1. Ashish Mathur 101.9K Reputation points Volunteer Moderator
    2025-11-26T23:19:43.8866667+00:00

    Hi,

    This M code in Power Query works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Grouped Rows" = Table.Group(Source, {"Project code"}, {{"Count", each _[#"Job #"]}}),
        Custom1 = Table.FromColumns(#"Grouped Rows"[Count],#"Grouped Rows"[Project code])
    in
        Custom1
    

    User's image

    Was this answer helpful?

    0 comments No comments

  2. Ashish Mathur 101.9K Reputation points Volunteer Moderator
    2025-11-26T23:15:43.3866667+00:00

    Hi,

    In cell D1, enter this formula

    =LET(p,A2:A7,j,B2:B7,h,TOROW(UNIQUE(A2:A7)),VSTACK(h,IFNA(DROP(REDUCE("",h,LAMBDA(s,c,HSTACK(s,FILTER(j,p=c)))),,1),"")))

    Hope this helps.

    User's image

    Was this answer helpful?

    0 comments No comments

  3. Hendrix-C 16,885 Reputation points Microsoft External Staff Moderator
    2025-11-26T17:34:15.3466667+00:00

    Hi @miguelalger,

    Thank you for your prompt update.

    If you want to make it more flexible, you can use the Power Query option. You can try using Power Query with these steps:

    1- Create Power Query table

    • Select all your data table > right click and choose Get Data from Table/Range > Check the option My table has headers > OK. This will open the Power Query editor.

    User's image

    • First step in Power Query editor, going to Add Column > Index Column > from 1

    User's image

    • Then select the Project code column and go to Transform > Pivot Column > set values column to Job# and advanced options as Don't aggregate.

    User's image

    • In the next interface, right click the Index column and click Remove. Then go to Home tab > Advanced editor > Delete all the M code in there and paste this instead:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table20"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project code", type text}, {"Job #", Int64.Type}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
        #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[#"Project code"]), "Project code", "Job #"),
        #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
        ProjectCols = Table.ColumnNames(#"Removed Columns"),
        ListsNoNulls = List.Transform(ProjectCols, (c) => List.RemoveNulls(Table.Column(#"Removed Columns", c))),
        #"Compacted Columns" = Table.FromColumns(ListsNoNulls, ProjectCols)
     
    in
        #"Compacted Columns"
    
    • After pressing Done, all null cells in your table will be removed like this. The last step is selecting Close & Load to output the table

    User's image

    • With Power Query, it will update the table with every change in your original cells (add new rows, change data number, etc.) but you will need to go to Query > click Refresh to update, not always update on any changes automatically.

    User's image

    To understand more about using PowerQuery to pivot tables, you can refer to Pivot columns (Power Query) | Microsoft Support.

    I hope this information is helpful. If you have any questions or need further assistance, please feel free to share them in the comments so I can continue to support you.

    I look forward to your response.

    Was this answer helpful?


  4. Hendrix-C 16,885 Reputation points Microsoft External Staff Moderator
    2025-11-26T15:59:06.0233333+00:00

    Hi @miguelalger,

    Thank you for posting your question in the Microsoft Q&A forum.

    Please notify me if I've misunderstood anything about your request. Based on your description, you have the original data like this: Project code (ABC, XYZ) in column A and Job# (01, 02, 11, 12) in column B. Then you want to transform like this: User's image

    The easiest and quickest way is using TRANSPOSE and FILTER formula. You can try following these steps to see if this helps:

    • First step is to create the column headers by using this formula: =TRANSPOSE(UNIQUE(A2:A5))

    User's image

    • After that, to fill the column with the job# code, you need to use this formula in cell E4: =FILTER($B$2:$B$5,$A$2:$A$5=E3). Then copy and paste the formula into cell F4.

    User's image

    Note: the data range in my formulas is based on my current test sheet. You will need to change the data range based on your working sheet to make sure the formulas work properly.

    I hope the information provided proves useful. Please proceed with the outlined steps and let me know whether they resolve the issue. If not, I’ll be glad to continue working with you to find a solution.    

    Thank you for your patience and understanding throughout this process. Should you have any questions or need further assistance, feel free to reach out at any time.    

    I look forward to hearing from you.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".          

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.