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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Seeking for a way to split the column which are not in same format

Hello everyone,
Morning!
 
I hope you guys are doing well.
Appreciate all your replies
 
I had a column in Power BI, where the data was not in the same format, and I am looking for splitting that column where it starts with year.
 
For example 
IDColumn
1PowerBI-Dax100-Microsoft-2018 (3 delimiters)
2PowerBI-Dax100-Microsoft-2018-2021 (4 delimiters)
3Power Automate-END100-2016 (2 delimiters)
4PowerBI-Automate-Dax100-End100- 2021-2021 (5 delimiter's)
I want to split that column where it starts with years.
 
Thank you everyone.
 
Looking forward for your responses.
1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Anonymous 

You can use split and merge in power query,  I duplicated the column and just remove the digits other the year by replace "100" with nothing, then you can just split by non-digits and digits.

 

Please copy the code in advanced editor or just download the example pbix to check the applied steps in query editor. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrIL08tcvLUdUmsMDQw0PXNTC7KL85PK9E1MjC0UIrViVYyIqQKSBgZgpUaw5QqOJaW5OcmlqTquvq5gHQA1ZmBlZggmQZXBDXWNS8FRCmAzIMaGgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Column", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column", "Column - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","100","",Replacer.ReplaceText,{"Column - Copy"}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Replaced Value", "Column - Copy", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column - Copy.1", "Column - Copy.2", "Column - Copy.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"Column - Copy.2", "Column - Copy.3"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Year")
in
    #"Merged Columns"

Vpazhenmsft_1-1635300899913.png

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

7 REPLIES 7
V-pazhen-msft
Community Support
Community Support

@Anonymous 

You can use split and merge in power query,  I duplicated the column and just remove the digits other the year by replace "100" with nothing, then you can just split by non-digits and digits.

 

Please copy the code in advanced editor or just download the example pbix to check the applied steps in query editor. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrIL08tcvLUdUmsMDQw0PXNTC7KL85PK9E1MjC0UIrViVYyIqQKSBgZgpUaw5QqOJaW5OcmlqTquvq5gHQA1ZmBlZggmQZXBDXWNS8FRCmAzIMaGgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Column", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column", "Column - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","100","",Replacer.ReplaceText,{"Column - Copy"}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Replaced Value", "Column - Copy", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column - Copy.1", "Column - Copy.2", "Column - Copy.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"Column - Copy.2", "Column - Copy.3"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Year")
in
    #"Merged Columns"

Vpazhenmsft_1-1635300899913.png

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

 

VahidDM
Super User
Super User

Hi @Anonymous 

 

Can you share a result table you are looking for?

 

Appreciate your Kudos!!

 

Anonymous
Not applicable

IDColumnResult column
1PowerBI-Dax100-Microsoft-20182018
2PowerBI-Dax100-Microsoft-2018-20212018-2021
3Power Automate-END100-20162016
4PowerBI-Automate-Dax100-End100- 2021-20212021-2021


Thanks for following up 

Hi @Anonymous 

 

Try this to add a new column:

Year Column = RIGHT([Column],LEN([Column])-SEARCH("20",[Column])+1)
 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!


Anonymous
Not applicable

Hi VahidDM, 


I am getting an error while using that function. 

The error was - "The Search Text provided to function SEARCH could not be found in the given text.


Thanks 

Hi @Anonymous 

 

That because there is value in the column that does not have year, so Try this:

 

Year Column =
IFERROR(RIGHT([Column],LEN([Column])-SEARCH("20",[Column])+1),blank())

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!




Anonymous
Not applicable

Thanks VahidDM,
 
It worked as I required. But It came up with a new problem where it was extracting wrongly for few columns.
 
For example
 
IDColumnResult column
1PowerBI-Dax100-Microsoft-20182018
2PowerBI-Dax201-Microsoft-2018-2021201-Microsoft-2018-2021
3Power Automate-END100-20162016
4PowerBI-Automate-Dax205-End100- 2021-2021Dax205-End100- 2021-2021
And here I want to say that for every value in that column has years at ending. 
 
I am looking to get only years out of that column.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors