Forum Discussion
Add dot after each character in string
- 3 years ago
This will not change data that has dots. If this isn't what you need, provide a complete sample of data and what should be modified. See directions below.
let Source = Excel.Workbook(File.Contents("C:\Users\Dante\Desktop\Monthly Country Reports\XXX\test.xlsx"), null, true), __activityqty_Sheet = Source{[Item="__activityqty",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(__activityqty_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"rel_region", type text}, {"rel_subregion", type text}, {"client", type text}, {"period", Int64.Type}, {"country", type text}, {"xcountry", type text}, {"activity", type text}, {"xactivity", type text},}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"period", "Date"}}), #"Duplicated Column" = Table.DuplicateColumn(#"Renamed Columns", "Date", "Date - Copy"), #"Reordered Columns" = Table.ReorderColumns(#"Duplicated Column",{"Date", "Date - Copy", "country", "activity", "xactivity",}), #"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"Date - Copy"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns1",{{"Date", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Date.FromText( Text.Range([Date], 0,4) & "-" & Text.Range([Date], 4,2) )), #"Changed Type2" = Table.TransformColumnTypes(#"Reordered Columns1",{{"Custom", type date}}), #"Removed Columns2" = Table.RemoveColumns(#"Changed Type2",{"Date"}), #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns2",{{"country", "CountryCode"}, {"Custom", "Date"},}), #"Changed Type3" = Table.TransformColumnTypes(#"Renamed Columns1",{{"CountryCode", type text},}), #"Inserted Text Between Delimiters" = Table.AddColumn(#"Changed Type3", "Text Between Delimiters", each Text.BetweenDelimiters([xsip], " ", " ", 1, 3), type text), #"Reordered Columns2" = Table.ReorderColumns(#"Inserted Text Between Delimiters",{"Date", "CountryCode", "activity", "xactivity",}), #"Removed Columns3" = Table.RemoveColumns(#"Reordered Columns2",{"Text Between Delimiters"}), #"Inserted Text After Delimiter" = Table.AddColumn(#"Removed Columns3", "Text After Delimiter", each Text.AfterDelimiter([xsip], " ", 1), type text), #"Reordered Columns3" = Table.ReorderColumns(#"Inserted Text After Delimiter",{"Date", "CountryCode", "activity", "xactivity",}), #"Removed Columns4" = Table.RemoveColumns(#"Reordered Columns3",{"Text After Delimiter"}), #"Reordered Columns4" = Table.ReorderColumns(#"Renamed Columns5",{"Date", "CountryCode", "activity", "xactivity",}), #"Renamed Columns6" = Table.RenameColumns(#"Reordered Columns4",{{"activity", "Activity_Code"}}), #"Split Column by Positions3" = Table.SplitColumn(#"Renamed Columns6", "xactivity", Splitter.SplitTextByPositions({0, 7}), {"xactivity.1", "xactivity.2"}), #"Changed Type7" = Table.TransformColumnTypes(#"Split Column by Positions3",{{"xactivity.1", type text}, {"xactivity.2", type text}}), #"Replaced Value2" = Table.ReplaceValue(#"Changed Type7","018","(2018",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2",")D",") D",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value4" = Table.ReplaceValue(#"Replaced Value3",")T",") T",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value5" = Table.ReplaceValue(#"Replaced Value4","019","(2019",Replacer.ReplaceText,{"xactivity.2"}), #"Filtered Rows1" = Table.SelectRows(#"Replaced Value5", each true), #"Replaced Value6" = Table.ReplaceValue(#"Filtered Rows1"," #(tab)Leadership","Leadership",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value7" = Table.ReplaceValue(#"Replaced Value6"," Crow","Crow",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value13" = Table.ReplaceValue(#"Replaced Value12"," (2","",Replacer.ReplaceText,{"xactivity.1"}), #"Filtered Rows2" = Table.SelectRows(#"Replaced Value13", each true), #"Trimmed Text" = Table.TransformColumns(#"Filtered Rows2",{{"xactivity.2", Text.Trim, type text}}), #"Renamed Columns8" = Table.RenameColumns(#"Changed Type8",{{"xactivity.1", "ActivityID"}}), #"Filtered Rows4" = Table.SelectRows(#"Trimmed Text1", each true), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows4",{"rel_region", "rel_subregion", "client", "xcountry"}), #"Added DotValues" = Table.AddColumn( #"Removed Columns", "With Dots", each let varLength = Text.Length([Data]), varData = [Data] in if Text.Contains(varData, ".") then varData else Text.BeforeDelimiter( Text.Combine( List.Generate( ()=> [x=0], each [x] < varLength, each [x = [x]+1], each Text.Middle(varData, [x], 1) & "." ) ), ".", varLength-1 ), type text ) in #"Added DotValues"How to get good help fast. Help us help you.
How To Ask A Technical Question If you Really Want An Answer
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.
Thanks ! It worked, however, the values that already have 'dots', have been added more dots...as shown in the image below
Of course. You didn't say you had some data with dots you didn't want modified. Do you have any other samples of data that I need to look out for?
- Anonymous3 years agoNot applicable
Actually i did...in Thursday's post.
Anyway, it works now. Thanks a lot for your help and patience !
- edhans3 years agoCommunity Champion
This will not change data that has dots. If this isn't what you need, provide a complete sample of data and what should be modified. See directions below.
let Source = Excel.Workbook(File.Contents("C:\Users\Dante\Desktop\Monthly Country Reports\XXX\test.xlsx"), null, true), __activityqty_Sheet = Source{[Item="__activityqty",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(__activityqty_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"rel_region", type text}, {"rel_subregion", type text}, {"client", type text}, {"period", Int64.Type}, {"country", type text}, {"xcountry", type text}, {"activity", type text}, {"xactivity", type text},}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"period", "Date"}}), #"Duplicated Column" = Table.DuplicateColumn(#"Renamed Columns", "Date", "Date - Copy"), #"Reordered Columns" = Table.ReorderColumns(#"Duplicated Column",{"Date", "Date - Copy", "country", "activity", "xactivity",}), #"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"Date - Copy"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns1",{{"Date", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Date.FromText( Text.Range([Date], 0,4) & "-" & Text.Range([Date], 4,2) )), #"Changed Type2" = Table.TransformColumnTypes(#"Reordered Columns1",{{"Custom", type date}}), #"Removed Columns2" = Table.RemoveColumns(#"Changed Type2",{"Date"}), #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns2",{{"country", "CountryCode"}, {"Custom", "Date"},}), #"Changed Type3" = Table.TransformColumnTypes(#"Renamed Columns1",{{"CountryCode", type text},}), #"Inserted Text Between Delimiters" = Table.AddColumn(#"Changed Type3", "Text Between Delimiters", each Text.BetweenDelimiters([xsip], " ", " ", 1, 3), type text), #"Reordered Columns2" = Table.ReorderColumns(#"Inserted Text Between Delimiters",{"Date", "CountryCode", "activity", "xactivity",}), #"Removed Columns3" = Table.RemoveColumns(#"Reordered Columns2",{"Text Between Delimiters"}), #"Inserted Text After Delimiter" = Table.AddColumn(#"Removed Columns3", "Text After Delimiter", each Text.AfterDelimiter([xsip], " ", 1), type text), #"Reordered Columns3" = Table.ReorderColumns(#"Inserted Text After Delimiter",{"Date", "CountryCode", "activity", "xactivity",}), #"Removed Columns4" = Table.RemoveColumns(#"Reordered Columns3",{"Text After Delimiter"}), #"Reordered Columns4" = Table.ReorderColumns(#"Renamed Columns5",{"Date", "CountryCode", "activity", "xactivity",}), #"Renamed Columns6" = Table.RenameColumns(#"Reordered Columns4",{{"activity", "Activity_Code"}}), #"Split Column by Positions3" = Table.SplitColumn(#"Renamed Columns6", "xactivity", Splitter.SplitTextByPositions({0, 7}), {"xactivity.1", "xactivity.2"}), #"Changed Type7" = Table.TransformColumnTypes(#"Split Column by Positions3",{{"xactivity.1", type text}, {"xactivity.2", type text}}), #"Replaced Value2" = Table.ReplaceValue(#"Changed Type7","018","(2018",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2",")D",") D",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value4" = Table.ReplaceValue(#"Replaced Value3",")T",") T",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value5" = Table.ReplaceValue(#"Replaced Value4","019","(2019",Replacer.ReplaceText,{"xactivity.2"}), #"Filtered Rows1" = Table.SelectRows(#"Replaced Value5", each true), #"Replaced Value6" = Table.ReplaceValue(#"Filtered Rows1"," #(tab)Leadership","Leadership",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value7" = Table.ReplaceValue(#"Replaced Value6"," Crow","Crow",Replacer.ReplaceText,{"xactivity.2"}), #"Replaced Value13" = Table.ReplaceValue(#"Replaced Value12"," (2","",Replacer.ReplaceText,{"xactivity.1"}), #"Filtered Rows2" = Table.SelectRows(#"Replaced Value13", each true), #"Trimmed Text" = Table.TransformColumns(#"Filtered Rows2",{{"xactivity.2", Text.Trim, type text}}), #"Renamed Columns8" = Table.RenameColumns(#"Changed Type8",{{"xactivity.1", "ActivityID"}}), #"Filtered Rows4" = Table.SelectRows(#"Trimmed Text1", each true), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows4",{"rel_region", "rel_subregion", "client", "xcountry"}), #"Added DotValues" = Table.AddColumn( #"Removed Columns", "With Dots", each let varLength = Text.Length([Data]), varData = [Data] in if Text.Contains(varData, ".") then varData else Text.BeforeDelimiter( Text.Combine( List.Generate( ()=> [x=0], each [x] < varLength, each [x = [x]+1], each Text.Middle(varData, [x], 1) & "." ) ), ".", varLength-1 ), type text ) in #"Added DotValues"How to get good help fast. Help us help you.
How To Ask A Technical Question If you Really Want An Answer
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables. - edhans3 years agoCommunity Champion
Awesome. Glad it is working as desired on your end!