Reputation: 159
guys!
I tried to create my custom function in Power Query and came across very unexpected and totally non-clear to me Err.
Function is simple -- it retrieves Name of the Student from Students Dictionary (it is called from Students Dictionary Table), then it retrieves tables of invoices and calculates how many invoieces were issued to this paticular Student.
code of the function is as following:
(FirstName as text) =>
let
Source = XeroInvoices,
#"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([XeroContacts.Name], FirstName) ),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"XeroContacts.Name"}),
#"Grouped Rows" = Table.Group(#"Removed Other Columns", {"XeroContacts.Name"}, {{"Result", each Table.RowCount(_), type number}}),
Result = Record.Field(#"Grouped Rows", {0}, "Result")
in
Result
Yet, as I call function with one argument, it says that three arguments were passed, and that the function expected two:
http://shot.qip.ru/00Qqzx-4Vmk2GJfF/
Could you please suggest what can be the problem with this all?
Thanks in advance.
Upvotes: 1
Views: 1402
Reputation: 1264
You can do it more simple way:
(FirstName as text) =>
let
Source = XeroInvoices,
FilteredTable = Table.SelectRows(Source, each Text.Contains([XeroContacts.Name], FirstName) ),
Result = List.Count(FilteredTable[XeroContacts.Name])
in
Result
Upvotes: 0
Reputation: 1588
The function that is causing the error-message is probably the last step of your function above:
Result = Record.Field(#"Grouped Rows", {0}, "Result")
It takes only 2 arguments: The record and the name of the field you want to catch. So try changing it to :
Result = Record.Field(#"Grouped Rows"{0}, "Result")
Find a tip on how to easily debug your M-functions here.
Upvotes: 3