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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
powerbricco
Frequent Visitor

change column value based on condition

Dear All,

I have a table that looks like this:

CodeValue1Value2
0001100200
000250500

0003

1020
0004150300

 

I'd like a condition in Power Query for which:

- if row meets Code = 0003, then Value1 and Value2 must be divided for 12.

I do not want to generate other columns, just want to substitute values in Value1 and Value2.

 

Desired result:

CodeValue1Value2
0001100200
000250500

0003

0,8333331,66666
0004150300

 

Thank you a lot

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@powerbricco add a replace value step and change it as shown below, do it for both value 1 and value 2

 

= Table.ReplaceValue(#"Changed Type",each [Value1],each if [Code] = 3 then [Value1] / 12 else [Value1], Replacer.ReplaceValue,{"Value1"})


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

5 REPLIES 5
parry2k
Super User
Super User

@powerbricco try this, change column name as per your table:

 

Table.ReplaceValue(#"Changed Type",each [Value],each if [Code] = 1 or [Code] = 2 or [Code] = 3 then Date.Month([Date]) else [Value],Replacer.ReplaceValue,{"Value"})


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.

v-shex-msft
Community Support
Community Support

Hi @powerbricco ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
parry2k
Super User
Super User

@powerbricco here is the output for [value1] after replace is applied.

 

parry2k_0-1738957940409.png

 



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

@powerbricco add a replace value step and change it as shown below, do it for both value 1 and value 2

 

= Table.ReplaceValue(#"Changed Type",each [Value1],each if [Code] = 3 then [Value1] / 12 else [Value1], Replacer.ReplaceValue,{"Value1"})


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.

Dear @parry2k , it does work perfectly!

May I ask you another advice?
Let's say I have a date column. Every time rows meet codes 001, 002, 003 and 0004, each Value1 should be replaced with month in date column. How can I write that?

Thank you a lot.. 

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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