• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Power Query- Replace Value|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Power Query- Replace Value|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryPower Query- Replace Value
sp_PrintTopic sp_TopicIcon
Power Query- Replace Value
Avatar
Vivian Wang
Member
Members
Level 0
Forum Posts: 30
Member Since:
March 4, 2020
sp_UserOfflineSmall Offline
1
August 25, 2022 - 8:24 pm
sp_Permalink sp_Print

Hi All,

I am trying to replace column A's value based on Column B.

So i have a column call "debtor name" and a column call "Internal External".

If "Debtor name" contains "Origin", replace internal with external in column "Internal External", otherwise dont make change on column "Internal External"

I wrote below and does not work, please help

=Table.ReplaceValue(#"previousstep",each[internal external],each if text.contains ([debtor name],"Origin") then "external" else [internal external], replacer.replacetext,{internal external})

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 441
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
2
August 25, 2022 - 8:41 pm
sp_Permalink sp_Print

Hi Vivian,

I believe it's better that you create the "Internal External" column by adding a custom column, like this:

Table.AddColumn(#"Previous Step", "Internal External", each if Text.Contains ([Debtor name], "Origin") then "External" else "Internal")

 

If that doesn't work for you, please upload an anonymized file so that we can see why not and come up with another solution.

 

Riny

Avatar
Vivian Wang
Member
Members
Level 0
Forum Posts: 30
Member Since:
March 4, 2020
sp_UserOfflineSmall Offline
3
August 25, 2022 - 9:23 pm
sp_Permalink sp_Print

Thanks Riny, I tried below code, got error message text.contains was not recognised, i have attached sample file.

So basically, in the sample date, if debtor name contains "origin", it would be classified as internal, which i wanna change it to external, other debtors remain their classification of internal/enternal in column of " Internal External".

much appreciated

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 441
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
4
August 25, 2022 - 10:11 pm
sp_Permalink sp_Print

OK. understood. Try attaching the file again. After adding a file, don't forget to press "Start upload" before you submit your reply.

Avatar
Vivian Wang
Member
Members
Level 0
Forum Posts: 30
Member Since:
March 4, 2020
sp_UserOfflineSmall Offline
5
August 25, 2022 - 11:00 pm
sp_Permalink sp_Print

thanks Riny, see attached.

Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 441
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
6
August 25, 2022 - 11:53 pm
sp_Permalink sp_Print sp_EditHistory

See if the attached file works for you. I connected to the date with PQ, applied some steps and loaded the end result back to Excel (the orange table in Sheet "Table1").

The steps imply that I first added a Custom column that checks if the debtor name has "origin" in it. If so, return EXTERNAL otherwise return the value from the "Internal External" column. I noted that there were some rows that didn't have something in "Internal External" and these caused errors. That's why I wrapped the code for the added column in "try" and "otherwise". Something similar to IFERROR in Excel.

Then I removed the original "Internal External" column, renamed the Custom column and reordered all columns. Perhaps not the most sophisticated solution but it's easy to follow and it works.

Avatar
Vivian Wang
Member
Members
Level 0
Forum Posts: 30
Member Since:
March 4, 2020
sp_UserOfflineSmall Offline
7
August 26, 2022 - 12:23 am
sp_Permalink sp_Print

Brilliant!! You rock, it is perfect.rnThanks for help.rnEnjoy the rest of your day. 

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Richard West, Rocco Pinneri, Alexandra Radu, AndyC
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.