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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
pedroccamaraDBI
Post Partisan
Post Partisan

Pivot or unpivot or transpose

Hi guys,
I hope everyone's ok
I got this need to transform these 4 columns on the right into 2 columns only according to this pic beside.
Inkedapagar_LI.jpg
Is it possible? Could you let me know how could i do it? I've try transpose, pivot and unpivot.....
Thanks in advance
Best regards

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @pedroccamaraDBI ,

 

I would create two separate queries then append them together.

 

1) Duplicate your original query

2) In your original query, remove columns 2 and 3

3) In your duplicate query, remove columns 5 and 6

4) In both queries, change column names so that they match EXACTLY (spelling, case etc.) to one another e.g. [SKU], [Type], [Value], [Week & Year]

5) Select your original query and go to Home tab > Append Queries, and choose whether you want to append the second table onto the bottom of the first, or create a brand new query that is the two source queries combined.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

One good way to do this would be to create a simple custom list of records as shown in this video.

Faster Data Transformations with List/Record M Functions - YouTube

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


jennratten
Super User
Super User

This is how you can accomplish the task.  Instead of pivot/unpivot you can simply stack the tables.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUSpKTQGSIJahvqG+kYGREZBpDOYaQbixOtFKIMGknNJUIGWEqtQEXSlIb3pRamoeEcaCNOcXJealE2OwKVCgoLSoICeVkMmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, Color = _t, Quantity1 = _t, Date1 = _t, Quantity2 = _t, Date2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Color", type text}, {"Quantity1", Int64.Type}, {"Date1", type date}, {"Quantity2", Int64.Type}, {"Date2", type date}}),
    Table1 = Table.RenameColumns ( Table.SelectColumns(#"Changed Type",{"Id", "Color", "Quantity1", "Date1"}), {{"Quantity1", "Quantity"}, {"Date1", "Date"}}),
    Table2 = Table.RenameColumns ( Table.SelectColumns(#"Changed Type" ,{"Id", "Color", "Quantity2", "Date2"}), {{"Quantity2", "Quantity"}, {"Date2", "Date"}}),
    CombineTables = Table.Combine ( { Table1, Table2 } )
in
    CombineTables

 

Before:

jennratten_0-1642165271567.png

 

AFTER:

jennratten_1-1642165294391.png

 

BA_Pete
Super User
Super User

Hi @pedroccamaraDBI ,

 

I would create two separate queries then append them together.

 

1) Duplicate your original query

2) In your original query, remove columns 2 and 3

3) In your duplicate query, remove columns 5 and 6

4) In both queries, change column names so that they match EXACTLY (spelling, case etc.) to one another e.g. [SKU], [Type], [Value], [Week & Year]

5) Select your original query and go to Home tab > Append Queries, and choose whether you want to append the second table onto the bottom of the first, or create a brand new query that is the two source queries combined.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hello @BA_Pete 
Thank you for your answer. I too prefer a simple solution,
Stay safe

Best regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors