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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
fg5
Regular Visitor

Rows with different schema

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 NAMETERMYEAR
TIMESTARTEND 
CLASSMathematics 1T12023
CLASSMathematics 2T12023
TIME14:0015:00 
TIME16:0017:00 
CLASSEnglishT22023

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:

NAMETERMYEARTIME
Mathematics 1T12023 
Mathematics 2T12023<List of TIME Records>
EnglishT22023 

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?

1 REPLY 1
wdx223_Daniel
Super User
Super User

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.