'Power BI Query Error - Expression.Error: 2 arguments were passed to a function which expects 3
I am new to Power BI Query. I have written this query to be able to calculate networkdays:
(Created as date, Closed as date, Holiday as list) as number =>
let
ListDates = List.Dates (Created, Number.From (Closed-Created), #duration(1,0,0,0)),
RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_, Day.Monday)< 5),
RemoveHolidays = List.RemoveItems (RemoveWeekends,Holiday),
CountDays=List.Count(RemoveHolidays)
in
CountDays
It has returned an error saying:
Expression.Error: 2 arguments were passed to a function which expects 3.
Details:
Pattern=
Arguments=[List]
Can anyone help me pinpoint what this error means and where I may have messed up the query?
Solution 1:[1]
Your function works as you intend. The error will be caused if you invoke the function by only specifying 2 of the 3 required arguments (Created, Closed and Holiday)
If you want to make your Holiday list an optional argument, you can adjust your function query like this, which will now work when only the first two arguments are specified;
(Created as date, Closed as date, optional Holiday as list) as number =>
let
ListDates = List.Dates (Created, Number.From (Closed-Created), #duration(1,0,0,0)),
RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_, Day.Monday)<5),
RemoveHolidays = try List.RemoveItems(RemoveWeekends,Holiday) otherwise RemoveWeekends,
CountDays = List.Count(RemoveHolidays)
in
CountDays
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Olly |
