Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jlauyfc1
Regular Visitor

Table.Pivot - without aggreagation but to list values

I am new to power query, how can I pivot a table without aggreagation but showing a list of (distinct) value? For example:

 

Table:

A | B

-----

a   X

b   X

 Y

 Y

e   Y

 

Expected result:

X | Y

-----

a   c

b  d

    e

 

Code:

What i am thinking about is:

 

= Table.Pivot(#"Source", List.Distinct(#"Source"[#"B"]), "B", "A", each .....)

 

 

Thanks in advance!!

1 ACCEPTED SOLUTION
Omid_Motamedise
Super User
Super User

use this formula

let
    Query1 = Table.FromColumns({{"a".."e"},{"X","X","Y","Y","Y"}},{"A","B"}),
    Pivot = Table.Pivot(Query1, List.Distinct(Query1[B]), "B", "A", each _),
    Custom1 = Table.FromRows(List.Zip({Pivot[X]{0},Pivot[Y]{0}}),Table.ColumnNames(Pivot))
in
    Custom1

 

it result in 

Omid_Motamedise_0-1725759196284.png

 


If my answer helped solve your issue, please consider marking it as the accepted solution.

View solution in original post

4 REPLIES 4
Omid_Motamedise
Super User
Super User

use this formula

let
    Query1 = Table.FromColumns({{"a".."e"},{"X","X","Y","Y","Y"}},{"A","B"}),
    Pivot = Table.Pivot(Query1, List.Distinct(Query1[B]), "B", "A", each _),
    Custom1 = Table.FromRows(List.Zip({Pivot[X]{0},Pivot[Y]{0}}),Table.ColumnNames(Pivot))
in
    Custom1

 

it result in 

Omid_Motamedise_0-1725759196284.png

 


If my answer helped solve your issue, please consider marking it as the accepted solution.

This is nicer with shorter coding. I amended your last line of code to make it work on any number of columns:

= Table.FromRows(List.Zip(Record.ToList(Table.First(Pivot))), Table.ColumnNames(Pivot))

 

Yes, it is dynamic and can work on any number, if you need more help or explanation just let me know


If my answer helped solve your issue, please consider marking it as the accepted solution.
tackytechtom
Super User
Super User

Hi @jlauyfc1 ,

 

How about this:

tackytechtom_0-1725731260547.png

 

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("i45WSlTSUYpQitWJVkqCs5KBrEgwKwXOSoWwYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"A", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"B"}, {{"Grouping", each _, type table [A=nullable text, B=nullable text]}}),
    #"Added Index" = Table.AddColumn(#"Grouped Rows", "Index", each Table.AddIndexColumn ( [Grouping], "Index", 1 )),
    #"Removed Columns 1" = Table.RemoveColumns(#"Added Index",{"B", "Grouping"}),
    #"Expanded Index" = Table.ExpandTableColumn(#"Removed Columns 1", "Index", {"A", "B", "Index"}, {"A", "B","Index"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Index", List.Distinct(#"Expanded Index"[B]), "B", "A"),
    #"Removed Columns 2" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns 2"

 

 

Let me know, if this solved your query.

 

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



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.