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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ale259
Helper I
Helper I

Pivot Columns Excel/ Power Query

Hello, 

I have the dateset as below (with fictional number)

HourlyA CityB City
12:00 AM1000200
1:00 AM5000400
2:00 AM70006000
3:00 AM80007000
4:00 AM10000800

 

And I want to change the data into this:

CityHourlyVisits
A City 12:00 AM1000
A City 1:00 AM5000
A City 2:00 AM7000
A City 3:00 AM8000
A City 4:00 AM10000
B City12:00 AM200
B City1:00 AM400
B City2:00 AM6000
B City3:00 AM7000
B City4:00 AM800

 

Can you give me any advice on how to do so? Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ale259,

 

Thank you for reaching out to Microsoft Fabric Community Forum.

 

Load the data into Power BI and open Power Query Editor by selecting Transform Data.
You can proceed step by step in Power Query to achieve your expected output.

 

Ensure the date column is converted to a time-only format. To do this, select the column and choose Time from the Data Type dropdown. This will display only the hourly values.

 

Select only the "Hourly" column, then go to Transform → Unpivot Other Columns. This will convert "A City" and "B City" into two columns: "Attribute" and "Value".

Rename "Attribute" to "City" and "Value" to "Visits".

 

Sort it from the filters dropdown in ascending or descending order.

 

Here is the output.

vvpabbu_0-1739342331951.png

 

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!

 

Regards,

Vinay Pabbu

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @ale259,

 

Thank you for reaching out to Microsoft Fabric Community Forum.

 

Load the data into Power BI and open Power Query Editor by selecting Transform Data.
You can proceed step by step in Power Query to achieve your expected output.

 

Ensure the date column is converted to a time-only format. To do this, select the column and choose Time from the Data Type dropdown. This will display only the hourly values.

 

Select only the "Hourly" column, then go to Transform → Unpivot Other Columns. This will convert "A City" and "B City" into two columns: "Attribute" and "Value".

Rename "Attribute" to "City" and "Value" to "Visits".

 

Sort it from the filters dropdown in ascending or descending order.

 

Here is the output.

vvpabbu_0-1739342331951.png

 

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!

 

Regards,

Vinay Pabbu

Thank you. This is a great answer!

Omid_Motamedise
Super User
Super User

Hi @ale259 

Writy click on Hourly column, and pick unpivot other columns.

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
dufoq3
Super User
Super User

Hi @ale259, chek this:

 

Output

dufoq3_0-1739297944891.png

 

v1

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjBQcPRV0lEyNDAwAFJGQDJWBygDlzCFSJhAJRA6zCESZgZQGWO4jAVExhwmY4JiiwFEhVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hourly = _t, #"A City" = _t, #"B City" = _t]),
    Unpivoted = Table.UnpivotOtherColumns(Source, {"Hourly"}, "City", "Visits"),
    SortedRows = Table.Sort(Unpivoted,{{"City", Order.Ascending}, {"Hourly", Order.Ascending}}),
    Reordered = Table.ReorderColumns(SortedRows,{"City", "Hourly", "Visits"})
in
    Reordered

 

v2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjBQcPRV0lEyNDAwAFJGQDJWBygDlzCFSJhAJRA6zCESZgZQGWO4jAVExhwmY4JiiwFEhVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hourly = _t, #"A City" = _t, #"B City" = _t]),
    Transformed = Table.FillDown(Table.Combine(List.Transform(List.Skip(Table.ColumnNames(Source)), each Table.FromColumns({{_}} & {Table.Column(Source, "Hourly"), Table.Column(Source, _)}, {"City", "Hourly", "Visits"}))), {"City"})
in
    Transformed

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi, do I need this part if I have this data range already? I don't qute understand what this long code mean. If you could explain it, it would be great. Thank you!

 Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjBQcPRV0lEyNDAwAFJGQDJWBygDlzCFSJhAJRA6zCESZgZQGWO4jAVExhwmY4JiiwFEhVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hourly = _t, #"A City" = _t, #"B City" = _t]),

Read note below my posts.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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