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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jonclay
Helper IV
Helper IV

Trying to change multiple values in one step

Hi everyone
I'm using the following code in an attempt to change multiple values all in one step:

= Table.ReplaceValue(
#"Renamed Columns",
each [Type],
each if [Type] = "157420000" then "A"
else if [Type] = "157420002" then "B"
else "C",
Replacer.ReplaceValue,{"Type"})

The issue I'm facing is that the code works if only one value is present in the Type field, but does not work if more than one comma-separated values are shown in the Type field. We use Dynamics CRM and the Type field is a multi-select option set field, so any ID can have multiple Types. I have shown some images below of what I mean:

ID 16638 has two comma separated types:

jonclay_0-1717600484856.png


ID 44406 has just the one type:

jonclay_1-1717600542355.png

However, when I run the above code, I'm getting 44406 showing as A (correctly) and 16638 showing as C when it should be B.

jonclay_2-1717600609277.png

I've wondered if I should be using Text.Contains or List.Contains, but I just can't seem to get the syntax correct.

Any help would be much appreciated.

Thank you
Jon

 



 

 




1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@jonclay here is what you can do, create a new blank query -> click advanced editor and paste the following M code, call this new query fnGetType (you can use whatever name you want)

 

(value) =>
let

    valueToList = Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)(value),
    valueToType = Text.Combine(List.Transform(valueToList, each if _ = "157420000" then "A" else if _ = "157420002" then "B" else "C"), "," )
    
in
    valueToType

 

now add a new column in your table with the following expression

 

fnGetType([Type])


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@jonclay good to hear. cheers!!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@jonclay if you want to use the replace function and not add a new column then change replace 

 

= Table.ReplaceValue( #"Changed Type", each [Type], each fnGetType([Type]),Replacer.ReplaceValue,{"Type"})

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@jonclay here is what you can do, create a new blank query -> click advanced editor and paste the following M code, call this new query fnGetType (you can use whatever name you want)

 

(value) =>
let

    valueToList = Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)(value),
    valueToType = Text.Combine(List.Transform(valueToList, each if _ = "157420000" then "A" else if _ = "157420002" then "B" else "C"), "," )
    
in
    valueToType

 

now add a new column in your table with the following expression

 

fnGetType([Type])


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k 

Fantastic, thank you so much. That works perfectly.

Best wishes,
Jon

jonclay
Helper IV
Helper IV

Hi @parry2k 

Yes please, that's exactly what I need.

Many thanks
Jon

parry2k
Super User
Super User

@jonclay So I guess you want each comma-separated value and then have multiple types, also comma-separated, correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.