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
nhoff
Advocate I
Advocate I

Expand column where not all records are tables

From an original XML-file I am trying to expand this column: 

 

Udklip1.JPG

When I do this, I get the following result:

 

Udklip2.JPG

 

Some records are not at the 'text'-level, some are still tables. If I mark one of the records with table value, I can see the following content:

 

Udklip3.JPG

 

If I now try to expand the column, I get the following error:

Udklip4.JPG

How do I expand the column?

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

This seems to be a bit tricky. You add a column that checks if the content of the current row of the column to expand is of type table. In that case you take the value as it is and if not, you transform the text-value to table. That way all fields will be in table format and can be expanded:

 

let

    Source = {1, #table({"a", "A"}, {{"b", "B"}})},
    #"In Tabelle konvertiert" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Step2 = Table.AddColumn(#"In Tabelle konvertiert", "Custom", each if Value.Is([Column1], type table) then [Column1] else #table({"ConvertedText"}, {{[Column1]}})),
    #"Erweiterte Custom" = Table.ExpandTableColumn(Step2, "Custom", Table.ColumnNames(Table.Combine(Step2[Custom])), Table.ColumnNames(Table.Combine(Step2[Custom])))
in
    #"Erweiterte Custom"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

25 REPLIES 25
Anonymous
Not applicable

Hi ImkeF.

 

I have inserted your code into a new query. Do I just need to change the source to my source?

 

I'm unsure as to amend your code so that it works on my source data.

 

Sorry for the dumb questions, I am new to Power BI!

 

Regards

 

Mike

Anonymous
Not applicable

Hi ImkeF,

 

I have managed to get this to work using your code.

 

Thank you so much for your help! 🙂

 

Regards

 

Mike

Anonymous
Not applicable

Hi ImkeF,

 

This line of code is returning a'null' when the value in Column1 is type table.

 

Step2 = Table.AddColumn(#"In Tabelle konvertiert", "Custom", each if Value.Is([Column1], type table) then [Column1] else #table({"ConvertedText"}, {{[Column1]}})),

Any idea why?

 

Thanks

 

Mike

Does is directly return a null or after you've expanded the column that this steps creates?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi Imke F,

 

It was after the expansion of the columns. I have figured it out now. It was due to the column heading being a new heading, and the expansion wanted to expand two columns, but it only expanded one.

 

Thanks

 

Mike

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.