• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Splitter.SplitTextByAnyDelimiter|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Splitter.SplitTextByAnyDelimiter|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QuerySplitter.SplitTextByAnyDelimiter
sp_PrintTopic sp_TopicIcon
Splitter.SplitTextByAnyDelimiter
Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
1
January 15, 2021 - 5:38 am
sp_Permalink sp_Print

Hello people, who knows how to split data by different delimiters BUT function must look through all rows. For example Splitter.SplitTextByAnyDelimiter() splits data and it takes as pattern data in the first row, if there will be 5 columns after splitting data in the first row then power query keep only 5 columns, even though second or third rows can produce 6 or 7 columns, data after 5th column from these rows actually is lost.

Best regards!

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
January 15, 2021 - 2:37 pm
sp_Permalink sp_Print

You cannot split each row into separate columns.

Add a column with Text.Split , you can pass a different separator to each row. The result will be a list, with List.FirstN you can keep only 5 items.

Then, you can combine the list back with a unique separator. Finally, split this column by the unique separator you specified.

All in one formula for a new column:

try Text.Combine(List.FirstN(Text.Split([Column1]," "),5),"|") otherwise null

Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
3
January 16, 2021 - 4:39 am
sp_Permalink sp_Print sp_EditHistory

Of course I can't and I don't try, I mean I have this function and three rows = Table.SplitColumn(#"Table Name", "Column Name", Splitter.SplitTextByAnyDelimiter({" ", ", ", "-"}, QuoteStyle.Csv)). 

1. USA State, City-County-Province

2. France-City-County-Province

3. United Kingdom-Great Britain-London-Europe, Example

As you know Splitter function will produce only 5 columns even though third row has more values and word Europe & London will not be shown in splitted  version of data.  

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
January 16, 2021 - 1:45 pm
sp_Permalink sp_Print

Hard to understand how you need to have the result, I'll have to guess.

I'll assume that you want to split into 5 columns AND keep whatever is after 5 elements into another column. Or you want 4 items in first 4 columns, and the rest in column 5?

Please provide clear descriptions next time, to save our time and get a faster and accurate solution, that's why a sample file with before and after examples is the best way to go.

Whenever I have a challenge, I go to the list of available power query functions searching for one that might fit my scenario.

In this case, if you want to have more than 1 delimiter add a new column with Text.SplitAny instead of Text.Split:
Text.SplitAny([Column1],"- ,")

Note that consecutive delimiters will create a blank item, you might want to replace in the entire column ", " with ","

In the new column, you will have each entry as a list of items, you can apply List functions to this column.
You can: add a column with Text.Combine(List.FirstN([Custom],5),"|")

You can split this column by the new delimiter, you will get 5 columns.

https://docs.microsoft.com/en-us/powerquery-m/list-firstn

Add now another column with: Text.Combine(List.RemoveFirstN([Custom],5),", ")

https://docs.microsoft.com/en-us/powerquery-m/list-removefirstn

This last column will have all items after 5 items.

Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
5
January 16, 2021 - 7:44 pm
sp_Permalink sp_Print

Thank you for response. I added the file to explain what I mean.
The main point is to split data by the longest string and with new added data in source to keep it updated. Spliitter functions gives hard coded columns names, how retrieve them and make them dynamic if they only occurs during this step?

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
January 17, 2021 - 3:18 pm
sp_Permalink sp_Print

I'm not able to open your pbix file, it's incompatible with my PBI version (Version: 2.84.981.0 64-bit (August 2020))

Can you provide the example of the desired result in excel?

Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
7
January 17, 2021 - 5:43 pm
sp_Permalink sp_Print

Yes, of course. I added. In the query that it is called AtemptToAutomate everything works until I add word in front of the longest string of text. For example, in third row if I add new words  at the end of cell in the source, number of columns increases but if I add new word in front of UnitedKingdom the query doesn't show proper number of columns. It looks like that it is limitation of Text.SplitAny function.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
8
January 17, 2021 - 6:57 pm
sp_Permalink sp_Print sp_EditHistory

Really don't understand what you mean.

I tried your query, with both scenarios:

-adding "/aaa" at the end of the third value,

-adding "aaa/" at the beginning of the third value.

The result is correct, I get 8 columns.

a1.jpgImage Enlarger

 

a2.jpgImage Enlarger

 

How can I replicate what you're saying?
Are you adding a delimiter NOT specified in Text.SplitAny? Please provide all details, don't let me guess what you did.

sp_PlupAttachments Attachments
  • sp_PlupImage a1.jpg (13 KB)
  • sp_PlupImage a2.jpg (17 KB)
Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
9
January 17, 2021 - 7:31 pm
sp_Permalink sp_Print

Here is a file, with problem. List.Max doesn't work properly, I can't see why. 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
10
January 17, 2021 - 8:50 pm
sp_Permalink sp_Print sp_EditHistory

List.Max cannot be used on text values, will apply an alphabetical text sorting, in your example list.max will return the text that starts with USA...

You have to transform from text to a count, use this step instead of what you have:

Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), List.Max(List.Transform(#"Added Custom"[Custom],each List.Count(Text.Split(_,";")
))))

Or, in 2 steps:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each List.Count(Text.SplitAny([Data]," /-"))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Combine(Text.SplitAny([Data]," /-"),";")),
#"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom.1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), List.Max(#"Added Custom1"[Custom]))
in
#"Split Column by Delimiter"

Or:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each Text.SplitAny([Data]," /-")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Combine(Text.SplitAny([Data]," /-"),";")),
#"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom.1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), List.Max(List.Transform(#"Added Custom1"[Custom],each List.Count(_))))
in
#"Split Column by Delimiter"
sp_AnswersTopicAnswer
Answers Post
Avatar
El Riz
Member
Members

Financial Modelling
Level 0
Forum Posts: 11
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline
11
January 17, 2021 - 9:25 pm
sp_Permalink sp_Print

Thank you very much! I've understood the problem with my approach.

Best regards!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: SALLY, Valentyn Kristioglo, Tiffany Kang
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Bruce Tang Nian
Scot C
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Forum Stats:
Groups: 3
Forums: 24
Topics: 6223
Posts: 27294

 

Member Stats:
Guest Posters: 49
Members: 31919
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.