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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
Community Champion
Community Champion

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors