+ Reply to Thread
Results 1 to 17 of 17

VBA and Power Query

  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    VBA and Power Query

    I have Excel 2013 and the latest version of Power Query.

    I am using Power Query to import the attached CSV file by each individual State (Column Labeled "Provider Business Practice Location Address State Name" which goes into Column AF after being imported) and then saving it. I have to do this each time 50+ times for each State or territory as, although this CSV file is only 13,667 rows, I have another CSV file just like this one that is 5 million rows and cannot fit into one Excel Sheet.

    Is there a macro that can automatically import and save 50+ Excel files grouped by each unique value in that column? I would imagine the macro would interact with Power Query, but if it could do it without Power Query, that would be fine too..Thanks.

    Providers.zip

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    Do you want to create a workbook for each state /territory listed in column "AF" ?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    Yes, a separate workbook for each State/Territory listed in Column AF. Thanks.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I have been doing a lot of research on this problem. While the download for Power Query is free, my system does not meet the requirements needed. The main point of my research has been on handling such a large file size with 5 million rows. As you pointed out, this won't fit in a standard size workbook.

    If this file were in database format before being converted into a CSV then using Power Query would be the best option. However, if the original file is a text file and you are using Power Query to export it as a CSV to Excel then converting the text file may not even be necessary. Can you post a sample of the original file?

  5. #5
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    The entire CSV can be downloaded at the following URL:

    http://nppes.viva-it.com/NPPES_Data_...April_2015.zip

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I am not sure how to handle this file. When decompressed, the file is 5.11 GB. This file is larger than all the space needed for Windows and Office on my computer. There is no Windows editor I know of that can open a file of this size. Is there no way to download the file in smaller chunks from the site?

  7. #7
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    No, which is why I was using Power Query to selectively import it..

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    Can you tell me how Power Query manages to recognize this as an Excel file when it clearly exceeds the Excel limits? This just doesn't make sense.

  9. #9
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    Power Query enables you to selectively import rows from a large CSV file into Excel.

    In this case, by specifying an individual State (e.g. Provider Business Practice Location Address State Name = CA), it will only import those rows that have "CA" in that field So, I am able to parse that large file by importing the States one at a time and saving them in their own unique workbook..

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I just tried out an idea. Actually it was my last resort. I successfully opened the file I saved to my hard drive after it was unzipped by using a Stream Object.

    Now I can import each line at a time into a worksheet until it is full and then start filling another worksheet. The header row can be included on each successive worksheet and each sheet can then be filtered.

    I think this will work.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I just finished running a test macro to read each line in the file to check if it would error out. It successfully read 4,551,495 lines without an error. Now I can start on the code to copy the lines on the worksheets, filter them and copy the states into their workbooks.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I just finished running a test macro to read each line in the file to check if it would error out. It successfully read 4,551,495 lines without an error. Now I can start on the code to copy the lines on the worksheets, filter them and copy the states into their workbooks.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    Do you need the data converted from text to the type for the column it will be in? For example, a date, or currency amount.

  14. #14
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    Just the ones that have dates in them (should be just two columns that have them - Enumeration Date and Last Update Date).

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA and Power Query

    Hello Brawnystaff,

    I have run into a problem with Excel. Despite the huge number of rows and columns on a worksheet, Excel is very memory limited. I can download 23 lines of data before I get "Excel is out of resources".

    This problem is independent of both my physical RAM (8GB) and hard disk (1TB) space. 23 rows at 330 columns is a pathetically small amount of worksheet space. I spent most of the day researching this problem and have not found any articles so far that explain this problem. All the solutions point to problems with excessive formatting, heavy formula use, Charts, etc. None of this applies in this situation.

    To say this frustrating is an understatement. Still hoping there may be a solution. Some articles point to 32 bit Excel having a limit of 2GB of resource memory and that switching to the 64 bit version overcomes this limitation. However, I don't think this a very practical solution for the end user.

  16. #16
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: VBA and Power Query

    Thanks for your work, Leith. Will do some more research to see what other options are available.

  17. #17
    Registered User
    Join Date
    05-16-2015
    Location
    Panama
    MS-Off Ver
    Office 365
    Posts
    2

    Re: VBA and Power Query

    What MSFT recommends in this type of scenarios is to load the data from that query directly into the Data Model (Power Pivot) so you can have hundreds of millions of arrows as required.

    There's another way of doing this but it does require a bit of work. Here are the steps:

    - Create the main query with all the data and add an index column in the final step
    - Create multiple Parameter tables with ranges (min and max for the index) and use them against your main query to get the ranges of rows that you need per worksheet

    To read more about the Parameter tables you can visit Ken's Blog here http://www.excelguru.ca/blog/2014/11...r-power-query/ and if you want to get to know more about combining multiple csv or even excel files you can visit this site as well http://powerquery.training/portfolio...ta-from-files/

    In future versions of Power Query you'll be able to use Macros and even VBA, but there's no documentation yet on how to use it as Office 2016 is still in preview.

    Hope this helps

+ 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. Power Query TNS Settings
    By Nerdio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2015, 08:24 AM
  2. Power Query how do i reuse on a new file
    By thorrrr in forum Excel General
    Replies: 3
    Last Post: 05-03-2014, 02:07 PM
  3. power point query
    By jrmehta in forum Excel General
    Replies: 1
    Last Post: 10-11-2010, 01:58 AM

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