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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
GW_J
New Member

Help with Transposing a table to create stacked bar charts

Hi,

 

I have a large table with many calculated columns and have been asked to create a report from the data using stacked bar charts.

 

The relevant part of the data is structured like so (the values are calculated columns):

 

KeyEquipmentPlanning TimeSet-up TimeOperationCleanout
1001Line 1306050020
1002Line 2153060060

 

I beleive for a stacked bar chart I would need the data tranposing like so:

 

KeyActionTime
1001Planning Time30
1001Set-up Time60
1001Operation500
1001Cleanout20
1002Planning Time15
1002Set-up Time30
1002Operation600
1002Cleanout60

 

I have tried creating a duplicate table in Power Query but this does not duplicate the calvculated columns. I also looked at creating a table in dax (New table = Old table) but that is not shown in power query for me to transpose the data (and my skills in dax are very limited).

 

Would really appreciate it if someone could point me in the right direction to help solve the issue.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

This is called "unpivoting"  and you do it in Power Query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUfLJzEtVADGMDYCEGYgwNQCRRgZKsTpgZUYwZSCGoSlCLVRHbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Equipment = _t, #"Planning Time" = _t, #"Set-up Time" = _t, Operation = _t, Cleanout = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Key","Equipment"}, "Action", "Time"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Time", Int64.Type}})
in
    #"Changed Type"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

This is called "unpivoting"  and you do it in Power Query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUfLJzEtVADGMDYCEGYgwNQCRRgZKsTpgZUYwZSCGoSlCLVRHbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Equipment = _t, #"Planning Time" = _t, #"Set-up Time" = _t, Operation = _t, Cleanout = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Key","Equipment"}, "Action", "Time"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Time", Int64.Type}})
in
    #"Changed Type"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Many thanks for the detailled explination! Very much appreciated.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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