Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dynamic Excel name handling in Power BI

I have a excel sheet named as ProductSales_YYYYMMDD.xls. and placed in a folder location.

 

Everyday in the same folder a new excel sheet get placed with current date. The new files will be in same column structure.

 

Now how to handle this scenario in Power BI for accepting new files every day with different name and same structure.

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi,  @Anonymous 

 

Yes, you can use 'Date.ToText( Date.From(DateTime.LocalNow()),"YYYYMMDD")' to select files dynamically.

Try like this in PQ :

 

 

 

let
    Source = Folder.Files(root&"FolderName"),
    temp = "ProductSales_"&Date.ToText(Date.AddDays( Date.From(DateTime.LocalNow()),1),"YYYYMMDD"),
    #"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([Name],temp)),
    custom = Table.Max(#"Filtered Rows","Name")[Content],
    #"Imported Excel" = Excel.Workbook(custom),
    Table1_Table = #"Imported Excel"{[Item="Table1",Kind="Table"]}[Data]
in
    Table1_Table

 

 

 

Best Regards

Janey Guo

 

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

View solution in original post

3 REPLIES 3
v-janeyg-msft
Community Support
Community Support

Hi,  @Anonymous 

 

Yes, you can use 'Date.ToText( Date.From(DateTime.LocalNow()),"YYYYMMDD")' to select files dynamically.

Try like this in PQ :

 

 

 

let
    Source = Folder.Files(root&"FolderName"),
    temp = "ProductSales_"&Date.ToText(Date.AddDays( Date.From(DateTime.LocalNow()),1),"YYYYMMDD"),
    #"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([Name],temp)),
    custom = Table.Max(#"Filtered Rows","Name")[Content],
    #"Imported Excel" = Excel.Workbook(custom),
    Table1_Table = #"Imported Excel"{[Item="Table1",Kind="Table"]}[Data]
in
    Table1_Table

 

 

 

Best Regards

Janey Guo

 

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

PC2790
Community Champion
Community Champion

As @Pragati11  mentione,d you wouldneed to go for folder approch.

You M query would look like something like this:

 

Source = Folder.Files(root&"FolderName"),
#"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Name], "ProductSales_"))

As the structuring and columns of all the files are same, you can go for merging all the files as per your requirement

Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can use folder approach in Power BI as a solution for this. Refer the following article:

https://powerbi.tips/2016/06/loading-data-from-folder/

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.