How can I split a column dynamically into multiple columns based on delimiter count

0 votes

How can I split a column dynamically into multiple columns based on delimiter count?
I have a column containing text strings separated by delimiters, but the number of parts varies by row. I want to split the column dynamically so that each piece becomes its own column, adjusting to the maximum number of delimiters present in the data. What is the most effective approach in Power Query to handle variable-length splits and avoid errors when expanding columns?

4 days ago in Power BI by Evanjalin
• 25,690 points
31 views

1 answer to this question.

0 votes

Instead of concentrating all those different delimiter-based separated columns into one Column, we dynamically split the Column into many columns from the maximum number of delimiters found for each row using Text. Split, List. Transform, and Table.ExpandListColumn functions. The end goal would be to get the maximum number of parts from different rows and expand them across without incurring any errors or faults in data. 

First, use Text.Split([Column], "Delimiter") (e.g., "") to turn the text string into a list. Since some rows have a different number of elements, it is now possible to transform these lists into structured columns by first converting them into records using Record.FromList and assigning dynamic column names such as Part1", "Part2", and so on to that. For example:

Table.TransformColumns(Source, {{"Column", each Record.FromList(Text.Split(_, ","), {"Part1", "Part2", "Part3", ...})}})

When the number of parts cannot be known in advance, scan the data first with List.Max(List.Transform(YourColumnList, each List. Count(Text.Split(_, ",")))) to figure out how many output columns you will generate. Finally, apply the use Table.ExpandRecordColumn to flatten the record into separate columns.

Such methods dynamically and excellently handle row entries with varied delimiter counts, preventing errors from absent components while keeping your data organized and neat for any subsequent transformation or analysis in Power BI.

answered 4 days ago by anonymous
• 25,690 points

Related Questions In Power BI

0 votes
1 answer

How do I dynamically rename multiple columns in Power Query based on a mapping table?

To dynamically rename multiple columns in Power ...READ MORE

answered Apr 1 in Power BI by anonymous
• 25,690 points
100 views
0 votes
1 answer

How can I create a dynamic grouping in Power Query where the group sizes vary based on another column’s values?

You can use these innovative techniques in ...READ MORE

answered Mar 17 in Power BI by anonymous
• 25,690 points
93 views
0 votes
1 answer
0 votes
1 answer

How can I create a multi-row card that dynamically adjusts based on the number of selected values?

To create a multi-row card in Power ...READ MORE

answered Mar 18 in Power BI by anonymous
• 25,690 points
71 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,090 points
1,598 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,090 points
2,936 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,520 points
1,721 views
+1 vote
1 answer

Connect power bi desktop to dataset and create custom reports

Open power bi report nd sign in ...READ MORE

answered Oct 10, 2023 in Power BI by Monika kale

edited Mar 5 1,884 views
0 votes
1 answer
0 votes
1 answer

How can I dynamically adjust column visibility in a paginated report based on user selections?

To dynamically adjust column visibility in a ...READ MORE

answered Mar 19 in Power BI by anonymous
• 25,690 points
51 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP