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
DanteL
Helper I
Helper I

Add dot after each character in string

I have a column like this

 

1234

2345

1133

4211

 

I need to add a dot/decimal after each number/character to show like the below

 

1.2.3.4

2.3.4.5

1.1.3.3

4.2.1.1

 

Thanks in advance !

1 ACCEPTED SOLUTION

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

15 REPLIES 15
DanteL
Helper I
Helper I

Sorry if i wasn't being clear enough.

 

I have a table called ABC with a column called ActivityID, and in it there's data like below

1111

1231

4321

1.2.3.4

5.3.2.1

5.3.9.3

 

I would like to convert those numbers without dots, e.g. 1111 to show as 1.1.1.1

 

I followed your instructions above and created a blank query and copied the code in it.

 

Then i went back to the ABC table and created a custom column called 'Custom' and changed the DATA table to ActivityID as shown below:-

 

 

 

Table.AddColumn(
            Source,
            "With Dots",
            each
                let
                    varLength = Text.Length([ActivityID]),
                    varData = [ActivityID]
                in
            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
        )

 

 

DanteL_0-1677732047819.png

and the result is as below:-

 

DanteL_0-1677724346681.png

 

Did i do it wrongly ?

If what you show is what you have, a simple one line algorithm suggests itself

 

Before

ronrsnfld_0-1678210204778.png

  • Transform the table column
    • create a List of the characters in the cell
    • remove any existing dots
    • Recombine the text using the dot as the delimeter
   #"Dotted" = Table.TransformColumns(#"Previous Step", 
        {"ActivityID", each Text.Combine(List.RemoveMatchingItems(Text.ToList(_),{"."}),".") })

To Reproduce, place the following into a blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQCpVgdIMPI2ATMMDE2goroGekZ60EETYEsIz1DONtSz1gpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ActivityID = _t]),
    #"Previous Step" = Table.TransformColumnTypes(Source,{{"ActivityID", type text}}),
    #"Dotted" = Table.TransformColumns(#"Previous Step", 
        {"ActivityID", each Text.Combine(List.RemoveMatchingItems(Text.ToList(_),{"."}),".") })
in
    #"Dotted"

 After

ronrsnfld_1-1678210289272.png

 

 

The 2nd line that says Source in your code. That should be the last line before this Add Columns. It might be #"Changed Type" or something similar. Those steps are on this page Utilizing M Code Samples Given as Solutions in Pow... - Microsoft Power BI Community I had linked to.

edhans_0-1677768891139.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@DanteL did you get it working? If not, can you post your M code and I will adjust it. use the </> button in the toolbar so formatting isn't lost.

edhans_0-1677857602450.png

 

 

Don't post images. I cannot copy and paste and edit images.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

 

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 Custom1" = Table.AddColumn(#"Removed Columns", "Custom", each Table.AddColumn(
            Source,
            "With Dots",
            each
                let
                    varLength = Text.Length([ActivityID]),
                    varData = [ActivityID]
                in
            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 Custom1"

 

This should work @DanteL 

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([ActivityID]),
                    varData = [ActivityID]
                in
            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"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks ! It worked, however, the values that already have 'dots', have been added more dots...as shown in the image below

 

DanteL_0-1678204700849.png

 

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? 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Actually i did...in Thursday's post.

 

Anyway, it works now. Thanks a lot for your help and patience !

Awesome. Glad it is working as desired on your end!



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

Also @DanteL be sure to read the link below. It will show you how to take my code and integrate it with yours.

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
DanteL
Helper I
Helper I

Thanks ! How do i apply the query to the targeted column in one of my tables ?

Change the [Data] field to your field name.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

Try this code.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlGK1YlWAtKmYIahobExmGFiZGioFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    DottedData =
        Table.AddColumn(
            Source,
            "With Dots",
            each
                let
                    varLength = Text.Length([Data]),
                    varData = [Data]
                in
            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
    DottedData

 

 

It returns this:

edhans_0-1677689489124.png

What it is doing:

varLength stores the length of the string

varData stores the value in the [Data] column to be used later

List.Generate loops through as many times as is the length (varLength) of the string, pulls out each character (that is what Text.Middle() is doing) and adds a period.
It generates a list of items, {1., 2., 3.} etc.
Text.Combine converts that list into one string, so 1.2.3.4.

Finally, Text.BeforeDelimiter pulls all data before that final period, so 1.2.3.4

 

I tested this with varying lengths. It will work.

edhans_0-1677689949630.png

 

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors