• 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

Add new column based on Criteria in another|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Add new column based on Criteria in another|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 QueryAdd new column based on Criteria in…
sp_PrintTopic sp_TopicIcon
Add new column based on Criteria in another
Avatar
Furqan Yousuf

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
April 21, 2021
sp_UserOfflineSmall Offline
1
April 21, 2021 - 3:36 am
sp_Permalink sp_Print

I downloaded statement from bank and based on certain value in the description field I want to assign value to it. For eg. I download transactions from bank and it has 3 columns (date, description, amount) I will add 4 the column next to amount called "Customer Name". If the description contains  "New York" "Manhattan" "Times Sq" (all three of them) the Customer Name will be NYC -- if desc contains "IL" Chicago" "O'hare" (again all 3 of them) the customer name will be "Chicago City" . Thanks

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
April 21, 2021 - 2:23 pm
sp_Permalink sp_Print

Hi Furqan,

You can add the new column with this formula:

if List.ContainsAll(Text.Split([Description]," "), {"New York", "Manhattan", "Times Sq"}) then "NYC" else if List.ContainsAll(Text.Split([Description]," "), {"IL", "O'hare", "Chicago"}) then "Chicago City" else null

Avatar
Furqan Yousuf

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
April 21, 2021
sp_UserOfflineSmall Offline
3
April 23, 2021 - 6:29 am
sp_Permalink sp_Print sp_EditHistory

power-query-question.jpgImage Enlarger

I need something like this (see attachment)

sp_PlupAttachments Attachments
  • sp_PlupImage power-query-question.jpg (65 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
April 23, 2021 - 12:59 pm
sp_Permalink sp_Print sp_EditHistory

Use a lookup table then, with 2 columns:
"City" Column 1 should have the city name, "Lookup" Column 2 should have a space separated text string with the matches: "New York Manhattan Times Sq" (only space separated, no other separator.)

Create this function with the name SearchText:

(TextString)=>
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"Lookup", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.ContainsAll(Text.Split(TextString," "), Text.Split([Lookup]," ")) then [City] else null),
#"Filtered Rows" = try Text.Combine(Table.SelectRows(#"Added Custom", each ([Custom] <> null))[Custom],", ") otherwise null
in
#"Filtered Rows"

You can use this function in your main query by adding a new column, calling this function:
= Table.AddColumn(Source, "Custom", each SearchText([Description]))

 

Note that a string like:"New Sq Times Manhattan York" will also return "New York", each space separates the match string into separate words, the formula will actually look after 5 words matches, not 3.
These posts might also help:

https://www.myonlinetraininghub.com/searching-for-text-strings-in-power-query

https://www.myonlinetraininghub.com/create-a-list-of-matching-words-when-searching-text-in-power-query

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Kim Knox
Guest(s) 9
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
Jessica Stewart: 204
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Jefferson Granemann
Glen Coulthard
Nikki Fox
Rachele Dickie
Raj Mattoo
Mark Luke
terimeri dooriyan
Forum Stats:
Groups: 3
Forums: 24
Topics: 6221
Posts: 27285

 

Member Stats:
Guest Posters: 49
Members: 31909
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.