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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
FreemanZ
Super User
Super User

How to convert txt (with blocks of variable length) to a table

Hi Community, 

 

I was trying to sort the kindle notes by booktitle. My notes look like:

 

booktitle1
AA
booktitle2
BB
CC
booktitle1
DD
booktitle1
EE
booktitle2
FF

or in table like:

booktitle1

AA
booktitle2
BB
CC
booktitle1
DD
booktitle1
EE
booktitle2
FF

 

I need to sort them by booktitle to a table like:

 

booktitle1

AA
DD
FF
booktitle2
BB
CC
EE

 

The tricky part is sometimes a note has multiple rows, like the BB CC note. 

 
Could anyone help with this challenge?
1 REPLY 1
ThxAlot
Super User
Super User

Simple enough

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSsrPzy7JLMlJNVSK1YlWcnQEU3BRIzDXyQlMOTujSkK0uLhgE3V1xWaQm5tSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Note = _t]),

    Grouped1 = Table.Group(Source, "Note", {"grp", Table.Skip}, 0, (x,y) => Byte.From(Text.Contains(y, "title", Comparer.OrdinalIgnoreCase))),
    #"Sorted Rows" = Table.Sort(Grouped1,{{"Note", Order.Ascending}}),
    Grouped2 = Table.Group(#"Sorted Rows", "Note", {"aggr", each Table.Combine([grp])[Note]}, 1),
    #"Combined Columns" = Table.CombineColumns(Grouped2, Table.ColumnNames(Grouped2), each {_{0}} & _{1}, "Notes"),
    #"Expanded Notes" = Table.ExpandListColumn(#"Combined Columns", "Notes")
in
    #"Expanded Notes"

 

ThxAlot_0-1693246077134.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.