+ Reply to Thread
Results 1 to 10 of 10

Dynamic CSV link in Power query

  1. #1
    Registered User
    Join Date
    10-19-2017
    Location
    italy
    MS-Off Ver
    2010
    Posts
    37

    Dynamic CSV link in Power query

    Hello everyone. I'm trying to setup a "dynamic" Excel Power query. What do I mean with dynamic? I need it to be able to let me choose a different CSV with a Macro or some sort of easy update. Problem is I can't find this function, I can only link it to a single file.

    Any help?

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: Dynamic CSV link in Power query

    You need to use the link to folder option. Then you will need a parameter query via which you can choose the files you wish to use. Hopefully forum PQ guru Olly will be along soon - he will be able to guide you better than I.
    Last edited by AliGW; 07-09-2019 at 04:29 AM. Reason: Typo
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Dynamic CSV link in Power query

    Assuming you want to query one specific CSV file, chosen manually, then put your filename in a cell, and define a Name for this cell. You can now refer to this named range directly in Power Query.

    For example, defining a named range called "MyFilename" for the cell containing the filepath / name:

    Please Login or Register  to view this content.
    Now you can manually update the filename in that cell, or use VBA to update it, then simply refresh your query.

    If you wanted to determine which CSV file to use, in a folder, based on criteria, then we could do that, too - but would need to better understand your requirement.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    10-19-2017
    Location
    italy
    MS-Off Ver
    2010
    Posts
    37

    Re: Dynamic CSV link in Power query

    I'd like to manually choose the CSV from the folder. Ideally, when I click on the refresh macro / query it prompts me with the folder of the CSVs and I select the correct one, which is uploaded and formatted using the rules of the query.

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Dynamic CSV link in Power query

    So, you could use a little VBA to choose the file and trigger the query refresh. Something like:

    Please Login or Register  to view this content.
    in the Workbook module.

  6. #6
    Registered User
    Join Date
    10-19-2017
    Location
    italy
    MS-Off Ver
    2010
    Posts
    37

    Re: Dynamic CSV link in Power query

    My bad, I forgot to mention that I'd like to not use VBA because of company restriction (the file will be shared and opened by different people). Is there a native way to do this?

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Dynamic CSV link in Power query

    If you want a click > prompt user experience, then you'll need VBA.

    If you want to avoid VBA, then simply manually enter the filename into the appropriate cell, then click Data > Refresh All.

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

    Re: Dynamic CSV link in Power query

    If you want GUI to pick csv...

    Why not just use Query Editor? Just double click on gear icon by "Source" step in Applied Steps.

    This will launch CSV import menu with option to browse for file.

    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

  9. #9
    Registered User
    Join Date
    10-19-2017
    Location
    italy
    MS-Off Ver
    2010
    Posts
    37
    Quote Originally Posted by CK76 View Post
    If you want GUI to pick csv...

    Why not just use Query Editor? Just double click on gear icon by "Source" step in Applied Steps.

    This will launch CSV import menu with option to browse for file.

    Attachment 631457
    Because I would have liked this to be user friendly cause it's going to be a company file. So, I hoped that power query had such an option by default. Thank you anyway.

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

    Re: Dynamic CSV link in Power query

    ? That's the default.

    But PQ is really meant for Data analyst and BI people. End users shouldn't be touching editor or changing source(s).

    If you want to make data source to be dynamic, and available for user interaction.
    What you'll need to do is design model and / or data storage, that others access via PowerPivot Data model, using single connection to multiple source.
    Though that will involve more than just PQ and Excel.

+ 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. Replies: 0
    Last Post: 03-24-2019, 09:18 AM
  2. Replies: 6
    Last Post: 03-18-2019, 02:02 PM
  3. [SOLVED] Creating Dynamic Parameters in Excel from link to Power Query
    By Stefj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2019, 06:58 AM
  4. Replies: 1
    Last Post: 11-12-2018, 02:46 PM
  5. Power query web link ?
    By common763 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-23-2018, 05:55 PM
  6. 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
  7. Dynamic Parameter Using Power Query
    By NeedForExcel in forum Excel General
    Replies: 1
    Last Post: 06-16-2016, 02:51 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