How do I pivot distinct values in Excel PivotTable fields editor?

AxD 691 Reputation points
2025-09-03T01:01:02.21+00:00

I have a table layout with different number of text values for each id column. Now, I'd like to pivot them, so that each id gets a single row and each text value is put into a different column of the id row:

Different number of columns and values

How can I do that using PivotTable Fields editor?

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Jade Ng 6,390 Reputation points Microsoft External Staff Moderator
    2025-09-03T03:08:13.6533333+00:00

    Dear @AxD,

    Thank you for your inquiry regarding the layout of text values in a standard PivotTable.

    In this case, please kindly allow me to provide some information with you: A standard PivotTable will not automatically spread each Text value into its own column for each ID. It will list them vertically.

    To achieve your desired layout, I recommend using a formula-based approach leveraging Excel's dynamic array functions (available in Excel 365 and Excel 2021).

    According to my test environment, here are these steps you can try and check if it helps:
    User's image

    Step 1: List Unique IDs

    Assuming your data is in columns B (ID) and C (Text), starting from row 2, enter the following formula in cell E2:

    =UNIQUE(B2:B10)

    Step 2: Spread Text Values Horizontally for Each ID

    In cell F2, enter the following formula and drag it to the right (e.g., G2, H2, etc.):

    =IFERROR(INDEX($C$2:$C$100, SMALL(IF($B$2:$B$10=$E2, ROW($B$2:$B$10)-ROW($B$2)+1), COLUMN(A1))), "")

    In older versions of Excel, please enter this as an array formula using Ctrl+Shift+Enter. In modern Excel, simply press Enter.

    This method will dynamically list each text value in its own column for the corresponding ID, providing a more intuitive and structured view of your data.

    I hope this information is helpful. Please follow these steps and let me know if it works for you.

    Thank you for your patience and your understanding. If you have any questions, please feel free to reach out.

    I'm looking forward for your reply.


    If my 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 threadUser's image

    1 person found this answer helpful.

  2. Andreas Killer 144K Reputation points Volunteer Moderator
    2025-09-03T11:01:59.09+00:00

    You have to perform some steps to get that working inside a Pivot table:

    1. Load the data using Power Query.
    2. Group the data by ID and add a local Index to each:

    Change

    = Table.Group(Source, {"ID"}, {{"AllRows", each _, type table [Id=number, Text=text]}})

    to

    = Table.Group(Source, {"ID"}, {{"AllRows", each Table.AddIndexColumn(_,"Index", 1, 1)}})

    1. Expand and load the table into the Data Model.
    2. Create a Pivot table from there.
    3. Add a measure MyText:

    =CONCATENATEX(Table1,Table1[Text],",")

    1. Drag ID into the Rows section, Index into the Columns section and MyText into then Values section.

    Andreas.

    0 comments No comments

  3. Ashish Mathur 100.8K Reputation points Volunteer Moderator
    2025-09-03T23:07:06.4066667+00:00

    Hi,

    In cell D2, enter this formula

    =LET(z,A2:A10,PIVOTBY(z,"Text "&BYROW(z,LAMBDA(a,COUNTIF(A2:a,a))),B2:B10,SINGLE,,0,,0))

    Hope this helps.

    User's image

    0 comments No comments

  4. Ashish Mathur 100.8K Reputation points Volunteer Moderator
    2025-09-03T23:10:39.16+00:00

    Hi,

    This Power Query M code works as well

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Grouped Rows" = Table.Group(Source, {"ID"}, {{"Count", each Table.AddIndexColumn(_,"Index",1,1)}}),
        #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Text", "Index"}, {"Text", "Index"}),
        #"Added Prefix" = Table.TransformColumns(#"Expanded Count", {{"Index", each "Text " & Text.From(_, "en-IN"), type text}}),
        #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Text")
    in
        #"Pivoted Column"
    

    User's image

    0 comments No comments

  5. IlirU 1,356 Reputation points Volunteer Moderator
    2025-09-04T08:58:02.16+00:00

    User's image

    Hi,

    Solution via formula and solution via Pivot Table.

    Assuming that your Data Source data is given in cells B3:C12 then apply the following formula in cell E3.

    =LET(d, IFERROR(TEXTSPLIT(TEXTJOIN(";",, BYROW(GROUPBY(B3:B12, C3:C12, ARRAYTOTEXT, 3, 0), ARRAYTOTEXT)), ", ", ";"), ""), IF(ISNUMBER(--d), --d, d))

    Attached is the link where you can download the file created by me and where the solution via Power Pivot is also given using formulas in Measure.

    Removed link

    HTH

    0 comments No comments

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.