Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Passing list items to functions with different argument requirements

I am attempting to have a function call an API request for each day of the year. I want to achieve this by having the function "Query2" make a call for each day which is provided by a pre-generated list.

Query2 Function:

(dayDate as date) as table =>
let
    Source = Xml.Tables(Web.Contents("https://API.EXAMPLE.com/api/stats/groups/104/interactions?d=" & Date.ToText(#date(dayDate)))),
    Table0 = Source{0}[Table],
    #"Changed Type" = Table.TransformColumnTypes(Table0,{{"media-type", type text}, {"origination", type text}, {"create-timestamp", type datetimezone}, {"wrap-up-code", type text}, {"wrap-up-text", type text}, {"is-interaction-completed", type logical}})
in
    #"Changed Type"

The table with generated dates is:

let
    DateRange= List.Dates(#date(2019,01,01),365,#duration(1,0,0,0)),
    Source = List.Transform(DateRange, each try {(_), Query2(_)} otherwise null),
    First = List.FirstN(Source, each _ <> null),
    Table = Table.FromRows(First, {"date", "Column1"}),
    #"Changed Type" = Table.TransformColumnTypes(Table,{{"date", type date}})
in
    #"Changed Type"

I am receiving one of two errors. The first comes with the above code:

An error occurred in the ‘’ query. Expression.Error: 1 arguments were passed to a function which expects 3.
Details:
    Pattern=
    Arguments=List

When the call for "Query2" is adjusted to "Query2(_,"","") I recieve the following error:

Expression.Error: 3 arguments were passed to a function which expects 1.
Details:
    Pattern=
    Arguments=List



So I am assuming I have at least two functions that have different expected number of arguments but do not know how to resolve this.

 

Thanks.

  • Anonymous 

     

    #date function needs 3 paramaters.

    Perhaps adjust the function as follows

     

    (dayDate as date) as table =>
    let
        Source = Xml.Tables(Web.Contents("https://API.EXAMPLE.com/api/stats/groups/104/interactions?d=" & 
    Date.ToText(#date(Date.Year(dayDate),Date.Month(dayDate),Date.Day(dayDate))))), Table0 = Source{0}[Table], #"Changed Type" = Table.TransformColumnTypes(Table0,{{"media-type", type text}, {"origination", type text}, {"create-timestamp", type datetimezone}, {"wrap-up-code", type text}, {"wrap-up-text", type text}, {"is-interaction-completed", type logical}}) in #"Changed Type"

1 Reply

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Anonymous 

     

    #date function needs 3 paramaters.

    Perhaps adjust the function as follows

     

    (dayDate as date) as table =>
    let
        Source = Xml.Tables(Web.Contents("https://API.EXAMPLE.com/api/stats/groups/104/interactions?d=" & 
    Date.ToText(#date(Date.Year(dayDate),Date.Month(dayDate),Date.Day(dayDate))))), Table0 = Source{0}[Table], #"Changed Type" = Table.TransformColumnTypes(Table0,{{"media-type", type text}, {"origination", type text}, {"create-timestamp", type datetimezone}, {"wrap-up-code", type text}, {"wrap-up-text", type text}, {"is-interaction-completed", type logical}}) in #"Changed Type"