Power Query Dynamic File Path & Name

DaytoData

New Member
Joined
Aug 22, 2017
Messages
3
I have a dynamic table called "NewFilePath" with a header "FILE_LOCATION" which I have imported into PowerQuery using the following M which works:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="NewFilePath"]}[Content],
    FileCriteria = Record.Field(Source{0},"FILE_LOCATION")
in
    FileCriteria

What I want to do is use the FILE_LOCATION value in instead of C:\Users\cmw1s\Documents\TEST_DATA_SOURCE.xlsx

Code:
let
    Source = Excel.Workbook(File.Contents([B]"C:\Users\cmw1s\Documents\TEST_DATA_SOURCE.xlsx"[/B]), null, true),
    TEST_DATA_Table = Source{[Item="TEST_DATA",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(TEST_DATA_Table,{{"DATE", type date}, {"DATA_VALUE", Int64.Type}})
in
    #"Changed Type"

I've tried the following, but received the error "Formula.Firewall: Query 'TEST_DATA' (step 'Changed Type') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination."

Code:
let
    NFP = NewFilePath,
    Source = Excel.Workbook(File.Contents(NFP), null, true),
    TEST_DATA_Table = Source{[Item="TEST_DATA",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(TEST_DATA_Table,{{"DATE", type date}, {"DATA_VALUE", Int64.Type}})
in
    #"Changed Type"

Any help would be greatly appreciated!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The easiest way is to adjust the privacy options:
Data tab - Get Data - Query Options - Privacy (under Current Workbook) - check "Ignore the Privacy Levels....(etc)"
 
Upvote 0
Hi Marcel

I have had this problem as well but I'm concerned about the caveat when selecting this setting about it possible exposing sensitive data to unauthorized people.

Can you put my mind to rest on this?


Thanks
Michael
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,250
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top