Forum Discussion
Extracting Data from Long String to Create Multiple Columns
- 6 years ago
Anonymous
Assuming you want the custom column immediately after the code you posted. You need to change Column1 in the last step to the name of the column where you have the text:
let Source = Csv.Document(File.Contents("C:\\history.csv"),[Delimiter=",", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}}), #"Removed Top Rows" = Table.Skip(#"Changed Type",6), #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Description", type text}, {"Symbol", type text}, {"Quantity", type number}, {"Price", Currency.Type}, {"Amount", Currency.Type}, {"Commission", Currency.Type}, {"Fees", Currency.Type}, {"Type", type text}, {"Security Description", type text}, {"Settlement Date", type date}}), #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type1", "Security Description", "Security Description - Copy"), #"Inserted Text Between Delimiters" = Table.AddColumn(#"Duplicated Column", "Text Between Delimiters", each Text.BetweenDelimiters([#"Security Description - Copy"], "$", "("), type text), #"Changed Type2" = Table.TransformColumnTypes(#"Inserted Text Between Delimiters",{{"Text Between Delimiters", Currency.Type}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Text Between Delimiters", "Strike Price"}}), #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Renamed Columns", {{"Security Description - Copy", each Text.BeforeDelimiter(_, "("), type text}}), #"Renamed Columns1" = Table.RenameColumns(#"Extracted Text Before Delimiter",{{"Security Description - Copy", "Options Strategy"}}), #"Duplicated Column1" = Table.DuplicateColumn(#"Renamed Columns1", "Security Description", "Security Description - Copy"), #"Inserted Text Between Delimiters1" = Table.AddColumn(#"Duplicated Column1", "Text Between Delimiters", each Text.BetweenDelimiters([#"Security Description - Copy"], "(", ")"), type text), #"Renamed Columns2" = Table.RenameColumns(#"Inserted Text Between Delimiters1",{{"Text Between Delimiters", "Ticker"}}), #"New Custom Col" = Table.AddColumn(#"Renamed Columns2", "Expiration date", each Date.From(Text.End(Text.Start([Column1],Text.PositionOf([Column1],"$")-1),9)), type date) in #"New Custom Col"Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Anonymous
Give me an example of what a string without the date would look like
Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
They typically are just text but occasionally haven numbers
| CONOCOPHILLIPS COM |
| REALITY SHS ETF TR NSD NXGN ECO ETF |
| ISHARES CORE U.S. AGGREGATE BOND ETF |
| VANGUARD CHARLOTTE TOTAL INTL BD INDEX |
| ISHARES CORE U.S. AGGREGATE BOND ETF |
| VANGUARD CHARLOTTE TOTAL INTL BD INDEX |
| REALITY SHS ETF TR NSD NXGN ECO ETF |
| CHEVRON CORP NEW COM |
| ISHARES CORE U.S. AGGREGATE BOND ETF |
| VANGUARD CHARLOTTE TOTAL INTL BD INDEX |
- AlB6 years ago
Community Champion
Anonymous
If no proper date is found the custom column we created earlier will throw an error. So just catch that with try-otherwise and return null in case of error. This is the updated code for the last step in the last query:
#"New Custom Col" = Table.AddColumn(#"Renamed Columns2", "Expiration date", each try Date.From(Text.End(Text.Start([Column1],Text.PositionOf([Column1],"$")-1),9)) otherwise null, type date)Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers