Transpose rows into columns into rows based on value in row

Cristan

New Member
Joined
Feb 5, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hey

I am trying to transpose rows into columns based on value in row:
1646919497205.png


So that every time a new number occurs in row 1, it moves to new row.
The outcome I'm looking for is this:
1646920767130.png


But the process needs to be automatic.

I am sorry for the bad explanation, I don't know how else to describe it, I hope it makes sense.

Thanks in advance!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
STOFNRPROEVEDATOMAENGDEATTRIBUT
52011-01-14
25​
52012-02-08
24​
52012-11-13
14,1​
52013-11-13
14​
52015-11-12
24,1​
52016-12-01
24​
52019-10-17
24,7​
132011-01-14
6,3​
132012-02-08
6,2​
132012-11-13
6,2​
132013-11-13
6,1​
132015-11-12
6,26​
132016-12-01
6,13​
132019-10-17
6,4​
152012-02-08
0,11​
252012-02-08
1,6​
352011-01-14
160​
352012-02-08
160​
362012-11-13
130​
362013-11-13
170​
362015-11-12
170​
362016-12-01
100​
362019-10-17
140​
362017-12-04
160​
502011-01-14
1,2​
502012-02-08
0,9​
502012-11-13
0,9​
502013-11-13
0,1​
502015-11-12
0,35​
502016-12-01
0,1​
502019-10-17
1,5​
532012-11-13
0,49180203​
532013-11-13
0,49180203​
582011-01-14
35​
582012-02-08
35​
582012-11-13
30​
582013-11-13
31​
582015-11-12
30​
582016-12-01
31​
582019-10-17
34​
582017-12-04
30​
592011-01-14
36,1​
592012-02-08
33,1​
 
Upvote 0
In Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tbl = Table.Group(Source, {"STOFNR"}, {{"All", each _}}),
    tbl1 = Table.TransformColumns(tbl, {{"All", each Table.FromRows(Table.ToColumns(_))}}),
    max = List.Accumulate(tbl1[All], 0, (s,c)=> let tcc = Table.ColumnCount(c) in if tcc>s then tcc else s),
    tcn = List.Accumulate({1..max}, {}, (s,c)=> s & {"Column" & Number.ToText(c)}),
    tbl2 = Table.ExpandTableColumn(tbl1, "All", tcn),
    Result = Table.RemoveColumns(tbl2,{"STOFNR"})
in
    Result

Book2
ABCDEFGHIJKLMN
1STOFNRPROEVEDATOMAENGDEATTRIBUTColumn1Column2Column3Column4Column5Column6Column7Column8
2540557255555555
35409472440557409474122641591423204270543755
454122614,1252414,11424,12424,7
554159114
654232024,113131313131313
75427052440557409474122641591423204270543755
854375524,76,36,26,26,16,266,136,4
913405576,3
1013409476,215
1113412266,240947
1213415916,10,11
1313423206,26
1413427056,1325
1513437556,440947
1615409470,111,6
1725409471,6
1835405571603535
1935409471604055740947
203641226130160160
213641591170
223642320170363636363636
233642705100412264159142320427054375543073
243643755140130170170100140160
253643073160
2650405571,250505050505050
2750409470,940557409474122641591423204270543755
2850412260,91,20,90,90,10,350,11,5
2950415910,1
3050423200,355353
3150427050,14122641591
3250437551,50,491802030,49180203
3353412260,49180203
3453415910,491802035858585858585858
355840557354055740947412264159142320427054375543073
365840947353535303130313430
37584122630
385841591315959
395842320304055740947
4058427053136,133,1
41584375534
42584307330
43594055736,1
44594094733,1
45
Sheet1
 
Upvote 0
Hey

Thank you for replying!

This is the result I'm looking for, but I cant seem to replicate it.
In my original i have made some changes before the result i sent you:

Power Query:
let
    Source = Excel.Workbook(File.Contents("\\PRO01\RDSdesktop$\cin\Desktop\Dataplatform og BI\Rune\2022-03-02-grundvandsanalyser (4).xlsx"), null, true),
    Sheet0_Sheet = Source{[Item="Sheet0",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet0_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"BOREHOLENO", type text}, {"KOMMUNE", type text}, {"BOR_ANVENDELSE", type text}, {"ANLAEGID", Int64.Type}, {"INDTNR", Int64.Type}, {"GRUMO_NR", type any}, {"XUTM32EUREF89", Int64.Type}, {"YUTM32EUREF89", Int64.Type}, {"PROEVEID", Int64.Type}, {"PROEVEDATO", type date}, {"STOFGRUPPE_KODE", Int64.Type}, {"STOFNR", Int64.Type}, {"MAENGDE", type number}, {"ATTRIBUT", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"ID", "BOREHOLENO", "KOMMUNE", "BOR_ANVENDELSE", "ANLAEGID", "INDTNR", "GRUMO_NR", "XUTM32EUREF89", "YUTM32EUREF89", "PROEVEID", "STOFGRUPPE_KODE"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"STOFNR", "PROEVEDATO", "MAENGDE", "ATTRIBUT"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"STOFNR", Order.Ascending}})
in
    #"Sorted Rows"

but i think i got, what you sent me added to that code correctly:

Power Query:
let
    Source = Excel.Workbook(File.Contents("\\PRO01\RDSdesktop$\cin\Desktop\Dataplatform og BI\Rune\2022-03-02-grundvandsanalyser (4).xlsx"), null, true),
    Sheet0_Sheet = Source{[Item="Sheet0",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet0_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"BOREHOLENO", type text}, {"KOMMUNE", type text}, {"BOR_ANVENDELSE", type text}, {"ANLAEGID", Int64.Type}, {"INDTNR", Int64.Type}, {"GRUMO_NR", type any}, {"XUTM32EUREF89", Int64.Type}, {"YUTM32EUREF89", Int64.Type}, {"PROEVEID", Int64.Type}, {"PROEVEDATO", type date}, {"STOFGRUPPE_KODE", Int64.Type}, {"STOFNR", Int64.Type}, {"MAENGDE", type number}, {"ATTRIBUT", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"ID", "BOREHOLENO", "KOMMUNE", "BOR_ANVENDELSE", "ANLAEGID", "INDTNR", "GRUMO_NR", "XUTM32EUREF89", "YUTM32EUREF89", "PROEVEID", "STOFGRUPPE_KODE"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"STOFNR", "PROEVEDATO", "MAENGDE", "ATTRIBUT"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"STOFNR", Order.Ascending}}),
    tbl = Table.Group(Source, {"STOFNR"}, {{"All", each _}}),
    tbl1 = Table.TransformColumns(tbl, {{"All", each Table.FromRows(Table.ToColumns(_))}}),
    max = List.Accumulate(tbl1[All], 0, (s,c)=> let tcc = Table.ColumnCount(c) in if tcc>s then tcc else s),
    tcn = List.Accumulate({1..max}, {}, (s,c)=> s & {"Column" & Number.ToText(c)}),
    tbl2 = Table.ExpandTableColumn(tbl1, "All", tcn),
    Result = Table.RemoveColumns(tbl2,{"STOFNR"})
in
    Result

But i get this error:
1647249199381.png


I hope this is enough info to make my problem clear.

Thank you for your help!

Best regards
 
Upvote 0

Forum statistics

Threads
1,223,671
Messages
6,173,735
Members
452,531
Latest member
Dufus1024

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