• 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

Refer always to the same folder in power query|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Refer always to the same folder in power query|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 QueryRefer always to the same folder in …
sp_PrintTopic sp_TopicIcon
Refer always to the same folder in power query
Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
1
November 21, 2019 - 2:43 am
sp_Permalink sp_Print

Hi,

i have 2 workbooks. From first one i am connecting it to second one (From SourceTable.xlsx to PowerQUeryResult.xlsx). 
I want user to refresh PQ query using button (not refresh on start- i supose there is option in PQ for this?). 

If SourceTable.xlsx exists in the same folder - refresh data. If not - keep table empty (put only "(blank)" in first row). 
It can be build in pivot or usual table - no matter. 

How to solve the issue?

Please help,
Jacek

sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4448
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
November 21, 2019 - 4:22 pm
sp_Permalink sp_Print

Hi Jacek,

Power Query doesn't have an option to refresh under the conditions you describe. This is a job for VBA. I'll move this post to the VBA forum.

Mynda

Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
3
November 21, 2019 - 4:54 pm
sp_Permalink sp_Print

Hi Mynda,

thank you very much. 

in PQ there is an option to handle errors using Try function. But i do not know how to implement it. The topic is not for VBA. 
I have 2 possible options:

1. Just do not refresh table if data is not there - leave table empty and do not show error.

I tried with:

let
Source = try (Excel.Workbook(File.Contents("C:\Users\admin\Desktop\Newest Pull request\PQ example\SourceTable.xlsx"), null, true)) otherwise null,
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Name", type text}, {"Surname", type text}})
in
#"Changed Type"

but i am getting that M is not returning list, only null. 

So how to not display error when user is refreshing PQ tables? 
Or how to input nulls into table when error is raised?

2. Create button in VBA to choose path where folder is. If file is not present, do not refresh tables. 

Best,
Jacek

Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
4
November 21, 2019 - 4:58 pm
sp_Permalink sp_Print

Or i can create empty row in Power Query somehow like here:

// create an empty record
EmptyRecord =
let
FieldNames = Record.FieldNames(FirstRecord),
EmptyValues = List.Repeat({""},Record.FieldCount(FirstRecord))
in
Record.FromList(EmptyValues,FieldNames),

 

If source file is not there add blank row to the table using Try. 

Please help with implementation,

Jacek

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4448
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
5
November 21, 2019 - 8:51 pm
sp_Permalink sp_Print

AFAIK refresh is not controlled from within the query. It either refreshes or it doesn't, in order for the query to 'see' if the file is there it needs to refresh the query and then it's too late because the refresh has already taken place.

I'll ask Catalin if he's aware of any way to do this in PQ, but my gut feel is that this isn't possible. You need VBA to check the file, then either refresh or not.

Mynda

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
November 21, 2019 - 9:06 pm
sp_Permalink sp_Print sp_EditHistory

Hi Jacek,

Try this:

try
   let
      Source = Excel.Workbook(File.Contents("C:\Users\Catalin\Desktop\New folder\SourceTable.xlsx"),      null,  true),
      Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
      #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Name", type text}, {"Surname", type text}})
   in
#"Changed Type"

otherwise #table({"Name", "Surname"}, {})

If source file is not found,  blank table with 2 columns is created: #table({"Name", "Surname"}, {})

sp_AnswersTopicAnswer
Answers Post
Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
7
November 22, 2019 - 4:57 pm
sp_Permalink sp_Print

O wow thank you very much!!

It is working like a charm! 

Best,

Jacek

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: RAQUEL ACION, Dana Friedt, Nada Perovic
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Forum Stats:
Groups: 3
Forums: 24
Topics: 6218
Posts: 27266

 

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