Forum Discussion

pat_energetics's avatar
pat_energetics
Advocate II
7 years ago
Solved

Get excel file from URL as custom function

Hi all, I have a table of excel file URLs as a result of a complex query to extract the underlying link addesses from the page  https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/P...
  • ImkeF's avatar
    7 years ago

    If my understanding is correct, this shouldn't be a problem, so there must be an error in your function or how you use it.

    Please check the following code that includes a mockup:

    let
    
    fn = (FileURL) =>
    let
        Source = Excel.Workbook(Web.Contents(FileURL), null, true),
        existingnstable_Table = Source{[Item="existingnstable",Kind="Table"]}[Data],
        #"Changed Type" = Table.TransformColumnTypes(existingnstable_Table,{{"Power Station", type text}, {"Owner", type text}, {"Nameplate Capacity (MW)", type number}, {"Technology Type", type text}, {"Fuel Type", type text}, {"Service Status", type text}, {"Region", type text}, {"summary_bucket", type text}, {"summary_status", type text}})
    in
        #"Changed Type",
    
        Source = "https://www.aemo.com.au/-/media/Files/Electricity/NEM/Planning_and_Forecasting/Generation_Information/May-2019/Generation_Information_QLD_May_2019.xlsx",
        #"Converted to Table" = #table(1, {{Source}}),
        #"Appended Query" = Table.Combine({#"Converted to Table", #"Converted to Table"}),
        #"Invoked Custom Function" = Table.AddColumn(#"Appended Query", "fn", each fn([Column1])),
        #"Expanded fn" = Table.ExpandTableColumn(#"Invoked Custom Function", "fn", {"Power Station", "Owner", "Nameplate Capacity (MW)", "Technology Type", "Fuel Type", "Service Status", "Region", "summary_bucket", "summary_status"}, {"Power Station", "Owner", "Nameplate Capacity (MW)", "Technology Type", "Fuel Type", "Service Status", "Region", "summary_bucket", "summary_status"})
    in
        #"Expanded fn"