cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Darko_Giac Regular Visitor
Regular Visitor

Importing Update Files from Folder Without Changing Sheet Name

Hi all, 

 

I'm currently working in Power Query and am exporting some survey data on a weekly basis to track the number of participants over the next month.

 

The variables in the export will not change from export to export, and since multiple files will live in the folder connected to power query, I have, through some great tips via this forum, been able to set up the connection so that it only pulls the most recent data export into excel.

 

However, each raw data export's sheet name will differ, and I was wondering if there is a way to by-pass that step. For instance, if one week, a file comes in with the sheet name "2018-11-01", but the following week's sheet is called "2018-11-02", I have to make sure that the sheet names are uniform across exports. Is there a way that power query can read in the updated data with different sheet names?

 

Thanks!

 

Darko

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-jiascu-msft Super Contributor
Super Contributor

Re: Importing Update Files from Folder Without Changing Sheet Name

Hi @Darko_Giac,

 

I would suggest we only change the necessary parts and leave the Power BI to generate other codes. The first line of your code can't run. It could be like below.

 

let
    Source = Folder.Files("D:\pbi_folder1"),
    #"D:\pbi_folder1\_ds xlsx" = Source{[#"Folder Path"="D:\pbi_folder1\",Name="ds.xlsx"]}[Content],
    #"Imported Excel" = Excel.Workbook(#"D:\pbi_folder1\_ds xlsx"),
    #"Added Index" = Table.AddIndexColumn(#"Imported Excel", "Index", 0, 1),
    Sheet1_Sheet = #"Added Index"{[Index=0,Kind="Sheet"]}[Data]
in
    Sheet1_Sheet

 

Screen-Capture-11-6-2018-11-09-00-AM

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 REPLIES 3
v-jiascu-msft Super Contributor
Super Contributor

Re: Importing Update Files from Folder Without Changing Sheet Name

Hi Darko,

 

There is a workaround which is almost elegant. Because the source is identified by name. We have to change it with other column having unique values. For example, an index column. 

If one file only has one sheet, that would be easy. Or you can find a way to make it easy to identify.

1. In the second step, add an index row. 

2. Change the code in the Advanced Editor like below.

let
    Source = Excel.Workbook(File.Contents("D:\data_source\ds2.xlsx"), null, true),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    Sheet1_Sheet = #"Added Index"{[Index=0,Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Name_Site", type text}, {"Name_Event", type text}, {"Date", type date}})
in
    #"Changed Type"

Importing-Update-Files-from-Folder-Without-Changing-Sheet-Name

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Darko_Giac Regular Visitor
Regular Visitor

Re: Importing Update Files from Folder Without Changing Sheet Name

Thanks for the response Dale!

 

I'm still having some issues getting this to work though. I noticed your solution was pulling from a workbook, but I would need to pull from a folder.

 

I'm trying to get the query below to work:

 

let
Source = Folder.Files(File.Contents("C:\PowerTracking\PracticeFolder), null, true),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
Sheet1_Sheet = #"Added Index"{[Index=0,Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Response ID", type text}})
in
#"Changed Type"

But running into the error:

 

Expression.SyntaxError: Token Comma expected (afterwhich it highlights the third line (#"Added Index")

v-jiascu-msft Super Contributor
Super Contributor

Re: Importing Update Files from Folder Without Changing Sheet Name

Hi @Darko_Giac,

 

I would suggest we only change the necessary parts and leave the Power BI to generate other codes. The first line of your code can't run. It could be like below.

 

let
    Source = Folder.Files("D:\pbi_folder1"),
    #"D:\pbi_folder1\_ds xlsx" = Source{[#"Folder Path"="D:\pbi_folder1\",Name="ds.xlsx"]}[Content],
    #"Imported Excel" = Excel.Workbook(#"D:\pbi_folder1\_ds xlsx"),
    #"Added Index" = Table.AddIndexColumn(#"Imported Excel", "Index", 0, 1),
    Sheet1_Sheet = #"Added Index"{[Index=0,Kind="Sheet"]}[Data]
in
    Sheet1_Sheet

 

Screen-Capture-11-6-2018-11-09-00-AM

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 310 members 3,469 guests
Please welcome our newest community members: