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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
lalithprasads
Frequent Visitor

Pivot Table - Don't Aggregate populating errors

Hello, I am trying Pivot and I get errors instead of names in two rows. please let me know what am i doing wrong? thank you.

 

pivot doubt 1.png

 

 

pivot doubt 2.png


I want to acheive something like this -

 

USA      IndiaEnglandBrazil
NickBalaKatePele
PulisikViratMountKaka
1 ACCEPTED SOLUTION

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8stMzlbSUQoNdlSK1YlWckrMSQRyPfNSMhPBAt6JJalAAde89JzEvBSwkG9+aV4JmlhAaU5mcSaySQGpOSCNTkWJVZk5UKOyE1FFwjKLEksQ1sUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sales man" = _t, Country = _t]),
    Partition = Table.Group(Source, {"Country"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Sales man", "Index"}, {"Sales man", "Index"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Partition", List.Distinct(#"Expanded Partition"[Country]), "Country", "Sales man"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Before creating a Pivot, you should assign occurence numbers to Countries in another column, say Index.  The first occurence of each country should show 1 and successive enries of that country should show 2,3 etc.  This can be done in the Query Editor.  Share data in a format that can be pasted in an MS Excel worksheet.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I have added the index and done pivoting and I get something like this with nulls -

 

pivot 3.png

 

 

How can I acheive something like this -

 

USA           IndiaEnglandBrazil
NickBalaKatePele
PulisikViratMountKaka

As requested in my previous measage, "Share data in a format that can be pasted in an MS Excel worksheet."


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur  here is the data, please help.

Sales manCountry
NickUSA
BalaIndia
KateEngland
MountEngland
PulisikUSA
PeleBrazil
KakaBrazil
ViratIndia

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8stMzlbSUQoNdlSK1YlWckrMSQRyPfNSMhPBAt6JJalAAde89JzEvBSwkG9+aV4JmlhAaU5mcSaySQGpOSCNTkWJVZk5UKOyE1FFwjKLEksQ1sUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sales man" = _t, Country = _t]),
    Partition = Table.Group(Source, {"Country"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Sales man", "Index"}, {"Sales man", "Index"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Partition", List.Distinct(#"Expanded Partition"[Country]), "Country", "Sales man"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur  It worked perfectly fine, but can you please explain me the m code? thanks. 

You are welcome.  Step through each step in the Applied steps section of the QUery Editor to understand what is happening.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Okay, thank you so much @Ashish_Mathur  

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.