Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
I have some timetable data for classes that is formatted in such a way that rows have different schema.
The first few rows define the column header for each different schema, one for CLASS, one for TIME and some others (removed for simplicity).
Any given TIME row will be related to the CLASS above it, and one class can have multiple times.
Nothing else relates a TIME to a CLASS other than its relative position.
Example:
| CLASS | NAME | TERM | YEAR |
| TIME | START | END | |
| CLASS | Mathematics 1 | T1 | 2023 |
| CLASS | Mathematics 2 | T1 | 2023 |
| TIME | 14:00 | 15:00 | |
| TIME | 16:00 | 17:00 | |
| CLASS | English | T2 | 2023 |
Here you can see only Mathematics 2 has classes, one from 14:00 to 15:00, and 16:00 to 17:00.
I want to turn each TIME row into a column in its corresponding CLASS as a list of records:
| NAME | TERM | YEAR | TIME |
| Mathematics 1 | T1 | 2023 | |
| Mathematics 2 | T1 | 2023 | <List of TIME Records> |
| English | T2 | 2023 |
Doing it in PowerShell or OfficeScript is trivial, but I need it in M.
I've tried accumulators, recursion, and a bunch of other stuff, but always hit a wall.
I have limited experience with functional programming and I feel like I'm fighting M, so my imperative programming brain must be getting in the way.
Any ideas?
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvZxDA5WUNJR8nP0dQVSIa5BvkAq0tUxSClWJ1opxBMsHBziGBQCpF39XICkAlgKrBXI800syUjNTSzJTC5WMAQZASKMDIyMcaoywlAFtcbQxMrAAESbQmgFFEkzqKQ5siTMfNe89JzM4gyQyUZwk2MB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
Custom1 = Table.Combine(Table.Group(Table.Skip(Source,2),"Column1",{"n",each if Table.RowCount(_)=1 then _ else Table.FromColumns(List.Zip({Record.ToList(_{0})})&List.Range(Table.ToColumns(Table.Skip(_)),1,2))},0,(x,y)=>Byte.From(y="CLASS"))[n])
in
Custom1
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 7 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 11 | |
| 10 | |
| 9 |