+ Reply to Thread
Results 1 to 13 of 13

Power Query VBA to Omit/Delete & Seperate Data From .CSV

  1. #1
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Hi Guys!

    I have a .CSV file which contains listings of horse races for a day which i have imported into Power Query and removed some columns of data that i dont need.

    Im only interested in The Horse Races that have 8,9,10,11 or 12 Runners. Because these files contain all the races for that day and no reference of how many runners for each race, how can i omit or delete all the other races and just leave 8,9,10,11 or 12 runner races?

    I would like to then load these into the worksheet but add a space between each race.


    The only way i could think is to add some VBA code within Power Query that once in race order counts how many Rows have the same start time and there for calculates how many runners there were. How can i manage this data?

    I appreciate any suggestions or help you may have, thanks for looking!


    I have included a copy of my workbook as i think its necessary.
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    You could create another query that groups by cols A and B and uses Countrows to determine the number of runners. Then filter that accordingly. You can then merge that query with your existing one so that only the matching rows on col A and B are included in the results.
    Rory

  3. #3
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    That sounds like it would work, thanks rorya!

    Im just not sure how to implement what you suggested. Would i load the CSV file into the worksheet then do what you said or could i do this somehow in Power Query using VBA?

  4. #4
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Right! i have done the first part which is great! How do i merge these back together, any idea?

    This i what i have..
    Attached Files Attached Files

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    There's a merge Queries button on the toolbar in PQ.

  6. #6
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Ive clicked that but now im abit lost as to how i should be merging them

    I cant quite get my head round it

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    This details the steps: https://www.powerquery.training/portfolio/merge-tables/

    Essentially you need to select the columns to join the queries on. I can't do it for you as I don't have your csv file and I have an older version of PQ.

  8. #8
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Aha!

    Thank you i have done that


    If i could just pick you brains one more time. I have the desired data in descending order now. Is there anyway to add a space in the rows between the different races? Basically by saying after all the rows with the same date and time then add a space before the next row

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    It might be possible but I confess I don't know how. It's kind of contrary to the purpose of PQ. You could load the data into a pivot table and add a blank row that way.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    For any data, I'd not recommend mixing in blanks. It's one of the worst thing you can do to data structure (considering subsequent analysis, charting etc).

    I'd recommend just using CF. Assuming [EVENT_DT] is in Column B.
    Select entire table's data body range.
    Use following formula in CF and apply bottom border format.
    =($B2<>$B3)

    Sample Result:
    0.JPG
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  11. #11
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Brilliant!


    Thats working guys thanks for your help and feedback left!

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Glad that it helped and thanks for the rep

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query VBA to Omit/Delete & Seperate Data From .CSV

    Ta much.

+ 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. [SOLVED] Power Pivot does not load new column added in Power query
    By ibuhary in forum Excel General
    Replies: 12
    Last Post: 02-19-2019, 03:53 AM
  2. Data consolidation - Power Query
    By abdumon7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2019, 11:26 AM
  3. Power query web data pull ?
    By common763 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-23-2018, 08:47 AM
  4. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  5. Power Query Error When No Data
    By seethesun in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-22-2018, 10:02 PM
  6. Replies: 0
    Last Post: 04-05-2018, 01:16 AM
  7. Replies: 2
    Last Post: 07-19-2015, 06:04 PM

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