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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jacek_k
Frequent Visitor

Extracting data from string - mixed column names and values

Hi Guys,

I have to extract data from strings. 100 columns and 10k+ rows.

Every row contains column names and corresponded values after semicolon but not each row contains each column.

I found solution but I think it is to complicated and can generate errors because of simply use of isOdd/isEven/FillDown functions. For example I had to add Tabel.Buffer to handle errors.

jacek_k_0-1652448116160.png

 

Is there easiest way to get the result?

Link to sample file on my onedrive:

Sample_file 

Regards

Jacek

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Maybe this will work better. I'm not sure it will, but it's worth a try.

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"To Tables" = Table.TransformColumns(#"Added Index",
        {{"Data", each
            let
                Pairs = List.Split(Text.Split(_, ";"), 2),
                ColNames = List.Transform(Pairs, each _{1}),
                ColValues = List.Transform(Pairs, each _{0})
            in
                Record.ToTable(Record.FromList(ColNames, ColValues))
            , type table}}
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"To Tables", "Data", {"Name", "Value"}, {"Name", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Data", List.Distinct(#"Expanded Data"[Name]), "Name", "Value")
in
    #"Pivoted Column"

 

The idea here is that the ColName;ColRowValue pairs are similar to how a record is structured [ColName=ColRowValue]. I split each text string into a list and then use List.Split to group it into pairs, taking the names from the first element of each pair and the values from the second element of each pair. Then turn that pair of lists into a record and then a table. Expand the tables and pivot on the names.

 

There may be some possible buffering optimizations but I'll let you experiment with that.

View solution in original post

2 REPLIES 2
jacek_k
Frequent Visitor

Hi, it works perfectly, i forgot to reply 😞

AlexisOlson
Super User
Super User

Maybe this will work better. I'm not sure it will, but it's worth a try.

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"To Tables" = Table.TransformColumns(#"Added Index",
        {{"Data", each
            let
                Pairs = List.Split(Text.Split(_, ";"), 2),
                ColNames = List.Transform(Pairs, each _{1}),
                ColValues = List.Transform(Pairs, each _{0})
            in
                Record.ToTable(Record.FromList(ColNames, ColValues))
            , type table}}
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"To Tables", "Data", {"Name", "Value"}, {"Name", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Data", List.Distinct(#"Expanded Data"[Name]), "Name", "Value")
in
    #"Pivoted Column"

 

The idea here is that the ColName;ColRowValue pairs are similar to how a record is structured [ColName=ColRowValue]. I split each text string into a list and then use List.Split to group it into pairs, taking the names from the first element of each pair and the values from the second element of each pair. Then turn that pair of lists into a record and then a table. Expand the tables and pivot on the names.

 

There may be some possible buffering optimizations but I'll let you experiment with that.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.