Forum Discussion

nisha_deepak's avatar
nisha_deepak
Helper III
5 years ago
Solved

Comma formatting

I have a field named Flood Details which is text type contains mix  of numbers plus text value like i show below.   i want to format number values with comma separated like this example below...
  • PhilipTreacy's avatar
    5 years ago

    Hi nisha_deepak 

    Please see this sample PBIX file for this M Code to do what you want.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLVMTAwUIrVATJ1TA3gHEMgC8ExAAMw2y+/RME5vyy1KDUFzIdoVVXIzcxTMETSo6sUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [all = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each try Number.ToText(Number.From([all]),"N") otherwise [all]),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each try if Text.Contains([Custom],".00") then Text.Start([Custom],Text.Length([Custom])-3) else [Custom] otherwise ""),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"})
    in
        #"Removed Columns"

     

     

    Regards

    Phil


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.