Forum Discussion

AllanBerces's avatar
AllanBerces
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

Dynamic Filename

Hi good day, can anyone help me on my PQ, the name of my data source change every week.. WK12..WK13 and so on. I want it to be dynamic.Can anyone help me to edit my PQ.    let Source = Excel.Workb...
  • Akash_Varuna's avatar
    Akash_Varuna
    1 year ago

    Hi AllanBerces Have you used the code that provided ? Maybe you have used but i couldnt see any ways could you try this please 

    let
        // Get the current week number (WK12, WK13, etc.)
        CurrentWeek = "WK" & Text.PadStart(Text.From(Date.WeekOfYear(DateTime.LocalNow(), Date.FirstDayOfWeek.Monday)), 2, "0"),
        
        // Construct the full file path dynamically
        FilePath = "https://company.sharepoint.com/sites/EASTWEST/Shared%20Documents/General/East%20West%20Current%20Act..." & CurrentWeek & ".xlsx",
        
        // Load the file from SharePoint
        Source = try Excel.Workbook(Web.Contents(FilePath), null, true) otherwise 
            error "File for " & CurrentWeek & " not found. Please check the file path or week logic.",
        
        // Access the 'Asset' sheet
        #"Asset_Sheet" = Source{[Item="Asset",Kind="Sheet"]}[Data],
        
        // Promote headers
        #"Promoted Headers" = Table.PromoteHeaders(#"Asset_Sheet", [PromoteAllScalars=true]),
        
        // Change column types
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers", {
            {"WON", Int64.Type}, 
            {"Location", type text}, 
            {"Complex/#(lf)Outstation", type text}, 
            {"Order Type", type text}, 
            {"Discpline", type text}, 
            {"Description", type text}, 
            {"Asset Cat. Tool (ACT)", type text}, 
            {"BSP Turnaround", type text}, 
            {"Execution Window", type any}, 
            {"BSP Estimate", Int64.Type}, 
            {"Est. hrs", type number}, 
            {"Active/#(lf)Inactive", type text}, 
            {"FWL", type text}, 
            {"INJECTED", type any}, 
            {"PENDING #(lf)CI", type text}, 
            {"DEFERRED/#(lf)CANCELLED", type text}
        })
    in
        #"Changed Type"