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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply

Need help converting multiple column groups to rows

Hi, I have a dataset/table that looks like this:-

 

1.jpg

* There is a Total_Pct column at the end which isn't shown in the picture above.

 

I wish to transform the table in Power Query such that it looks like this:-

 

FrequencySexAlcohol consumed_NumberAlcohol consumed_Percent
Never usedMale373223
Never usedFemale694119
Never usedUnknown14233
Never usedTotal1111320.2
Have used, but not in last 30Male260816
Have used, but not in last 30Female640317
.
.
.
   

 

How can I do that? Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Hi @slorin / Stéphane,


Thank you so much for the above code. I am still new to M, and I am unable to resolve this error message. Please take a look at the picture below.

 

Thanks a lot in advance!

 

2.jpg

View solution in original post

3 REPLIES 3
slorin
Super User
Super User

Hi,

...Alcohol consumed_Percent = number ])

 

Stéphane 

Hi @slorin / Stéphane,


Thank you so much for the above code. I am still new to M, and I am unable to resolve this error message. Please take a look at the picture below.

 

Thanks a lot in advance!

 

2.jpg

slorin
Super User
Super User

Hi,

 

let
Source = YourSource,
Sex = List.ReplaceValue(Table.ColumnNames(Source)," Freq.","",Replacer.ReplaceText),
Data = Table.FromRows(
List.TransformMany(
Table.ToRows(Source),
each {1,3,5,7},
(x,y) => {x{0},Sex{y},x{y},x{y+1}}),
type table [Frequency = text, Sex = text, Alcohol consumed_Number = Int64.Type, Alcohol consumed_Percent = type number ])
in
Data

 

Stéphane 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.