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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PowerBITesting
Helper IV
Helper IV

Replacing comma separated values to texts with creating a New column

Trying to create a Column with below Logic 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine( List.ReplaceMatchingItems(Text.ToList ([CommaSeparatedNumbersColumnName]), { {100,"A" },{"200","B" },{"300","C" },{",","." } })),type text)

 

expected result

100,200,300 ---> A.B.C

100------------->A

100,200 --------->A,B

 

Note : only {",","." }  this part replaced 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@PowerBITesting - You can use SUBSTITUTE in DAX:

New Column = 
  SUBSTITUTE(
    SUBSTITUTE(
      SUBSTITUTE([Column],"100","A"),
      "200","B"
    ),
    "300","C"
  )

Should be able to do the same thing in Power Query essentially nesting your replacer functions. @ImkeF @edhans  



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
edhans
Super User
Super User

Try this @PowerBITesting 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQw0DECYmMDA6VYHTAfRkPEYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Added Custom" = 
        Table.AddColumn(
            Source, 
            "Custom", 
            each 
            Text.Combine(
                List.ReplaceMatchingItems(
                    {Text.Split([Column1], ",")}{0},
                    {{"100","A"},{"200","B"},{"300","C"}}
                ),"."
            )
        )
in
    #"Added Custom"

 

 

It generates this (NOTE: Above code properly replaces the comma with period. My screenshot below doesn't reflect that)

edhans_0-1599669082435.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
Greg_Deckler
Super User
Super User

@PowerBITesting - You can use SUBSTITUTE in DAX:

New Column = 
  SUBSTITUTE(
    SUBSTITUTE(
      SUBSTITUTE([Column],"100","A"),
      "200","B"
    ),
    "300","C"
  )

Should be able to do the same thing in Power Query essentially nesting your replacer functions. @ImkeF @edhans  



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@PowerBITesting , if they are comma-separated number then use  Text.Split in place of Text.ToList and try

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak - did you try your suggestion? It just returns an error when I try that simple replacement.



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 , There was a formula give with the result and I assumed it working and text.Split will convert comma-separated text string and that is what suggested. Seem like that is needed too. 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

That is why I was asking @amitchandak . If I read @PowerBITesting 's original post correctly, they were getting the column with the red (1) below, and wanted what shows up in column marked with the red (2).

edhans_0-1599670543704.png

But I still cannot get your solution to replace Text.ToList with Text.Split. It returns an error, and doesn't do the proper replacement of 100 with A, 200, with B, etc.

But I could be wrong. That is why I was asking if you tested it as I'd like to see your solution to better understand. I have been unable to get it to work.



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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.