Transpose and combining data

Riddlessaffa

New Member
Joined
Sep 9, 2016
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a sheet of data with half hourly (i.e. 00:00; 00:30; 01:00 etc) listed in the top row and the date in the fist colum with a kWh value in the corresponding cell. Is there a way I can combine the the date and the half hourly value to make all the date and times be listed in one colum and the corresponding kWh in the next colum?

This is how it currently looks:
Date00:0000:3001:0001:3002:0002:30
01/10/2022
79​
77​
78​
77​
77​
78​
02/10/2022
88​
90​
87​
73​
75​
72​
03/10/2022
88​
89​
82​
75​
92​
88​

This is how I need it to look:

Date TimekWh
01/10/2022 00:00​
79
01/10/2022 00:30​
77
01/10/2022 01:00​
78
01/10/2022 01:30​
77
01/10/2022 02:00​
77
01/10/2022 02:30​
78

I have a full 2 years worth of data to do. Is there a way to do it using Power Query. I tried but couldn't figure it out.

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Thanks. I'm on Office 365 Version 2311 if that helps. Will update account details now.
 
Upvote 0
Thanks for that.
How about
Fluff.xlsm
ABCDEFGHIJ
1Date00:0000:3001:0001:3002:0002:30
201/10/202279777877777801/10/2022 00:0079
302/10/202288908773757201/10/2022 00:3077
403/10/202288898275928801/10/2022 01:0078
501/10/2022 01:3077
601/10/2022 02:0077
701/10/2022 02:3078
802/10/2022 00:0088
902/10/2022 00:3090
1002/10/2022 01:0087
1102/10/2022 01:3073
1202/10/2022 02:0075
1302/10/2022 02:3072
1403/10/2022 00:0088
1503/10/2022 00:3089
1603/10/2022 01:0082
1703/10/2022 01:3075
1803/10/2022 02:0092
1903/10/2022 02:3088
20
Sheet6
Cell Formulas
RangeFormula
I2:J19I2=HSTACK(TOCOL(IF(B1:G1<>"",A2:A4))+TOCOL(IF(A2:A4,B1:G1)),TOCOL(B2:G4))
Dynamic array formulas.
 
Upvote 0
Solution
Another option with power query (although it's probably a bit messy)
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type time}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Attribute", type number}, {"Date", Int64.Type}}),
    #"Inserted Addition" = Table.AddColumn(#"Changed Type1", "Addition", each [Date] + [Attribute], type number),
    #"Reordered Columns" = Table.ReorderColumns(#"Inserted Addition",{"Addition", "Date", "Attribute", "Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Date", "Attribute"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns",{{"Addition", type datetime}})
in
    #"Changed Type2"
 
Upvote 0
Just for fun. A bit cleaner version of the PQ solution.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
    DateTime = Table.AddColumn(Unpivot, "DateTime", each DateTime.From(Int64.From([Date]) + Decimal.From(Time.FromText([Attribute])))),
    ROC = Table.TransformColumnTypes(Table.SelectColumns(DateTime,{"DateTime", "Value"}),{{"DateTime", type datetime}, {"Value", Int64.Type}})
in
    ROC
 
Upvote 0
Thanks for that.
How about
Fluff.xlsm
ABCDEFGHIJ
1Date00:0000:3001:0001:3002:0002:30
201/10/202279777877777801/10/2022 00:0079
302/10/202288908773757201/10/2022 00:3077
403/10/202288898275928801/10/2022 01:0078
501/10/2022 01:3077
601/10/2022 02:0077
701/10/2022 02:3078
802/10/2022 00:0088
902/10/2022 00:3090
1002/10/2022 01:0087
1102/10/2022 01:3073
1202/10/2022 02:0075
1302/10/2022 02:3072
1403/10/2022 00:0088
1503/10/2022 00:3089
1603/10/2022 01:0082
1703/10/2022 01:3075
1803/10/2022 02:0092
1903/10/2022 02:3088
20
Sheet6
Cell Formulas
RangeFormula
I2:J19I2=HSTACK(TOCOL(IF(B1:G1<>"",A2:A4))+TOCOL(IF(A2:A4,B1:G1)),TOCOL(B2:G4))
Dynamic array formulas.
Thank you Fluff. This will work. I would never have figured that out. Much appreciated.
 
Upvote 0
Just for fun. A bit cleaner version of the PQ solution.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
    DateTime = Table.AddColumn(Unpivot, "DateTime", each DateTime.From(Int64.From([Date]) + Decimal.From(Time.FromText([Attribute])))),
    ROC = Table.TransformColumnTypes(Table.SelectColumns(DateTime,{"DateTime", "Value"}),{{"DateTime", type datetime}, {"Value", Int64.Type}})
in
    ROC
Thank you. I might give this a try when I'm feeling a bit braver to tackle coding in PQ. :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top