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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Mai_Tran
Regular Visitor

Tranpose a table without using Transpose UI

Hi guys

 

I have a file like this

 

Mai_Tran_0-1770890494308.png

I want to tranpose it into this

Mai_Tran_2-1770890608621.png

 

I did it successfully using Tranpose UI, but I am finding another way, just code manually to do it.

 

Do you guys have any ideas to do it just with M code?

File in the link 

 

https://docs.google.com/spreadsheets/d/1zz00s_rJ1DPEHL6MWxv8PuT_L5x2OUO2/edit?usp=drive_link&ouid=10...

 

Thanks

 

 

1 REPLY 1
AlienSx
Super User
Super User

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    headers = {"Region", "Manager", "Year", "Quarter", "Month", "Revenue"},
    rows = List.Buffer(Table.ToList(Source, (x) => x)),
    periods = List.Buffer(List.Zip(List.Transform(List.Range(rows, 1, 3), (r) => List.Skip(r, 2)))),
    trx = List.TransformMany(
        List.Skip(rows, 4),
        (x) => List.Zip({periods, List.Skip(x, 2)}),
        (x, y) => List.FirstN(x, 2) & y{0} & {y{1}}
    ),
    result = Table.FillDown(Table.FromList(trx, (x) => x, headers), headers)
in
    result

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.