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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
madilee
New Member

How do i perform pivot for a file that has 2 columns in row and one column in value

In my excel file, there are 3 columns with header name sku,location and carton id. I will normally pivot in excel by pulling sku then followed by location in row field and then carton id in value field.  The value field is to count the number of carton id. 

How do I do it in power query?

3 REPLIES 3
smozgur
Helper I
Helper I

  1. Select the location column.
  2. Click the Pivot Column button in the Transform ribbon tab.
  3. Select carton_id as the Values Column.
  4. Click OK.

Here is the sample M code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRSgRiQ6VYnWglI2MTIDsJiI2Q+CB5YzDf2MQUyE4GYhOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), {"sku", "location", "carton_id"}),
    ChangeTypes = Table.TransformColumnTypes(Source,{{"sku", type text}, {"location", type text}, {"carton_id", Int64.Type}}),
    
    PivotColumn = Table.Pivot(ChangeTypes, List.Distinct(ChangeTypes[sku]), "sku", "carton_id", List.Sum)
in
    PivotColumn

 

Hi Smozgur, 

 

Thank you for your reply. I am very new to Power Query, would appreciate if you could explain in more details.

 

Below is my file in excel:

madilee_2-1690819061273.png

 

 

After i pivot the file, below is the intended results:

madilee_0-1690818823056.png

This is how the layout is in pivot:

 

madilee_1-1690818894000.png

 

What do i do to get the same results in power query? 

Thank you. 

Anonymous
Not applicable

Hi @madilee ,

 

You can follow my steps to fix it.

1.Both select [Move From Loc] and [Sku] columns and right-click one of them to choose "Group By...".

15.png2.Set up “Group By” as follows. The Total column will cont the ID group by [Move From Loc] and [Sku].

vstephenmsft_0-1690856204007.png

vstephenmsft_1-1690856212158.png

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.