Forum

7.03 Dynamic Folder...
 
Notifications
Clear all

7.03 Dynamic Folder Paths

3 Posts
2 Users
0 Reactions
76 Views
(@malcala)
Posts: 18
Eminent Member
Topic starter
 

Hy Mynda. 

In the code you provided, the "source files" are hard coded. Is there any way to make this dynamic as well?
What I need is a query from a folder that contains a set of xlsx about 30 files. There is a folder for each month, for example 2101, 2102, 2103, 2104 and so on. So I need a query that dynamically takes the source.
I tried to do this by creating a parameter called SourceFile and using Text.From() but it is not working.

let
    //Get Excel Files from a Folder
    Path = Excel.CurrentWorkbook(){[Name="PathTable"]}[Content],
    Source = Folder.Files(Text.Combine({Path[FolderPathColumn]{0} ,Text.From(SourceFile)},"")),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Excel.Workbook([Content])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Content"})
in
    #"Removed Columns"
 

in a Second try I copy the whole folderpath in the PathTable and instead SourceFile I put "" as follows:

Source = Folder.Files(Text.Combine({Path[Path]{0} ,""},"")),

it worked:)  Now the question is. Is there a way to see the whole Name of the files when expanding the columns?

in my case the Problem is, that the file names have the following structure: PK_LK_20.xlsx 

in step 2 source (see sample image below): I can see the file name as follows: PK_LK_20.xlsx 

2021-04-07-22_17_28-Query1-Power-Query-Editor.png

but in step 6 Expanded Custom (see sample image below): I just see PK for all the files name

2021-04-07-22_18_08-Query1-Power-Query-Editor.png

In this way I am unable to see exactly which files I want to kepp or take out. It would be helpful to get the rest of the name after the underscore.

Do you have any suggestions?

I really appreciate your help.Laugh

Thanks in advance

 
Posted : 08/04/2021 2:38 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Maria,

In step 3, 'Remove Other Columns', make sure you keep the column that contains the file name.

Mynda

 
Posted : 08/04/2021 7:44 pm
(@malcala)
Posts: 18
Eminent Member
Topic starter
 

Thank you very much!! Mynda, 

it worked!!Laugh

 
Posted : 09/04/2021 1:53 am
Share: