+ Reply to Thread
Results 1 to 10 of 10

Power Query - how remove everything but XX-XX-XX from a string of text

  1. #1
    Registered User
    Join Date
    04-25-2019
    Location
    canada
    MS-Off Ver
    365
    Posts
    66

    Power Query - how remove everything but XX-XX-XX from a string of text

    Hello,
    Is it possible to use Power Query to remove from a text string everything but the substrings that end with 4 digits starting either with 19XX or 20XX? For example, in the attached file, one of the cells in column B has the following string:

    Quote
    all, all radiators, dimensions 1, freightliner, freightliner-cascadia, freightliner-cascadia-2017, freightliner-cascadia-2018, freightliner-cascadia-2019, freightliner-cascadia-2020, freightliner-cascadia-2021, radiator 1 year warranty, radiator pt, spinimages=16
    Unquote

    I need to remove everything BUT:

    freightliner-cascadia-2017, freightliner-cascadia-2018, freightliner-cascadia-2019, freightliner-cascadia-2020, freightliner-cascadia-2021

    Basically, if the sub-string does not end on a year, I want to remove it. Comma is a delimiter between substrings.
    Attached Files Attached Files
    Last edited by Ballet4ever; 06-25-2024 at 11:56 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,771

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    In the attached, I was able to split the data in Power Query so that each item is on a row by itself. I was then able to remove the suggested items. You can see this new table. I then tried to repivot the data in Power Pivot so that it was in the same format as you had as your source data. Power Pivot could not allow this as it indicated that each cell would exceed the character limit. Perhaps you can work with what I have supplied.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,543

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    If you allow the use of macros then you will do it with such a fairly simple code (result in column C):
    Please Login or Register  to view this content.
    Artik

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    Making the data into a table called Table1, then this should work:

    Please Login or Register  to view this content.
    See attached.
    Attached Files Attached Files
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    Alternate Vba Solution...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 06-25-2024 at 08:13 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    04-25-2019
    Location
    canada
    MS-Off Ver
    365
    Posts
    66

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    Great! Thank you.

  7. #7
    Registered User
    Join Date
    04-25-2019
    Location
    canada
    MS-Off Ver
    365
    Posts
    66

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    thank you, it works, but not quite as I need it - it leaves some "undesirable" substrings like: "international-(navistar)-7000". In this example 7000 is not a year. I only need substrings that end on a year, like this one "international-(navistar)-7000-2010"

  8. #8
    Registered User
    Join Date
    04-25-2019
    Location
    canada
    MS-Off Ver
    365
    Posts
    66

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    Thank you very much, but I cannot use macros.

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    but I cannot use macros.
    pity...provides correct results...

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Power Query - how remove everything but XX-XX-XX from a string of text

    Small change required:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove . 0 1 2 3 4 5 6 7 8 9 using power query
    By daliye in forum Excel General
    Replies: 4
    Last Post: 12-03-2023, 03:14 PM
  2. [SOLVED] REmove a Line Feed with Power Query
    By AllisterB in forum Excel General
    Replies: 1
    Last Post: 10-22-2022, 06:36 AM
  3. Replies: 10
    Last Post: 08-01-2022, 08:05 AM
  4. [SOLVED] Power Query - Transform to remove dash next to a letter and not between numbers in string
    By beijing0305 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-20-2022, 10:32 AM
  5. [SOLVED] Power Query remove one row if duplicated
    By Undo in forum Excel General
    Replies: 2
    Last Post: 05-03-2022, 01:24 AM
  6. Replies: 10
    Last Post: 06-25-2020, 12:19 AM
  7. Remove Special Character within Power Query
    By excelnovice19 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 03-09-2019, 11:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1