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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DivyanshuTotla
New Member

how to extract column values on basis of certain characters and creating new column?

Basically i am having column as "Win By" which contain the info about the team win. so i want to extract the column values into two columns which is "Win By Run" and "Win by Wicket". the output is given below

Input:

Win ByWin By RunWin By Wicket
8 Runs  
7 wickets  
20 Runs  

 

output:

Win ByWin by RunsWin by wickets
8 Runs 
7 wickets 7
20 Runs20 

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use these two formulas in two custom columns

= if Text.Contains([Win By],"Runs", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null

= if Text.Contains([Win By],"Wickets", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WslAIKs0rVorViVYyVyjPTM5OLYHwjAygMrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Win By" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Win by Runs", each if Text.Contains([Win By],"Runs", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Win By Wickets", each if Text.Contains([Win By],"Wickets", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null, Int64.Type)
in
    #"Added Custom1"

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Use these two formulas in two custom columns

= if Text.Contains([Win By],"Runs", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null

= if Text.Contains([Win By],"Wickets", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WslAIKs0rVorViVYyVyjPTM5OLYHwjAygMrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Win By" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Win by Runs", each if Text.Contains([Win By],"Runs", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Win By Wickets", each if Text.Contains([Win By],"Wickets", Comparer.OrdinalIgnoreCase) then Text.Split([Win By]," "){0} else null, Int64.Type)
in
    #"Added Custom1"
HotChilli
Super User
Super User

Remove the columns 

Win By Run Win By Wicket

 (maybe they are just there as an example anyway)

--

Split the 'Win By' column on space. Then Pivot the column that has the runs/Wickets  type in it.

You'll need a unique identifier on each row - maybe you have this already, if not add an index before the Pivot

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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
Top Kudoed Authors