Search code examples
excelpowerquerym

excel m power query passing a table to a function


I am trying to pass a query (which returns table) inside another function as below, but I am getting below error, Expression.Error: We cannot convert a value of type Table to type Function. Details: Value=Table, Type=Type

below is the code.

#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each fxRetry(Insider([Value]))),

so above fxRetry is a recursive function that is taking another query Insider([Value]) as input and that returns a table. below is the code of fxRetry, this function just recall the Insider([Value]),again and again till it responds, shown below is the fxretry code.. Where I need to solve the above expression error, I am new to excel m query, any guidance please where I need to do type cast or change in code..

let
    Source = (MyCall as function) =>
let
Buffered = Binary.Buffer (MyCall() ),
Output = if Record.Field(try Buffered , "HasError") = false then 
Buffered else 
Function.InvokeAfter(()=>@fxRetry(MyCall), #duration(0,0,0,5) )
in 
Output
in
Source

Note: Below is the format of the source Insider([Value]) query,

(stock as text) as table =>
let
    Source = Csv.Document(Web.Contents("https://www.nseindia.com/api/corporates-pit?index=equities&from_date="&FromDate()&"&to_date="&ToDate()&"&symbol="& stock &"&csv=true", [Headers=[#"accept-encoding"="gzip, deflate", #"accept-language"="en-US,en", #"user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36", Cookie=""& cookie() &""]]),[Delimiter=",", Columns=29, Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    .....
in
    #"Renamed Columns"

Solution

  • Insider([Value]) isn't a function.

    This seems like very complicated code for someone new to Excel and PQ. Where has it come from? I'd go back to the source if I were you.