Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(IDCustErr as number)=>
let
//IDCustErr = 5, /* for debugging purposes */
// ============ START: Define your list of custom error records here ====================
ListCustomErrors = {
//Custom error #1: The only permissible tax rates are as follows 7% and 19%
[
CustErrID = 1,
reason ="Illegal tax rate",
message = "The only allowed tax rates are 7% and 19%!",
detail = "Make sure in your data source, that only those 2 tax rates are included!",
InternalDescription = "When ever another tax rate comes up, throw this error record"
],
//Custom error #2:
[
CustErrID = 2,
reason ="Reason Error 2",
message = "Message Error 2",
detail = "Details Error 2",
InternalDescription = "INternal Description Error 2"
]
/*
Define as many other custom error records, as you want/ need here
*/
},
// ============ END: Define your list of custom error records here ====================
//Convert the list into a table
ListToTable = Table.FromList(ListCustomErrors, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
//Expand the table
ExpandColumn = Table.ExpandRecordColumn(ListToTable, "Column1", {"CustErrID", "reason", "message", "detail",
"InternalDescription"}, {"CustErrID", "reason", "message", "detail", "InternalDescription"}),
//This step filters the table down to the record, which has the custom error ID that you passed to the function with 'IDCustErr'
FilterForCustErrID =
try
//Try to call the CustErrID
Table.SelectRows(ExpandColumn, each ([CustErrID] = IDCustErr)){0}
otherwise
//if the CustErrID doesn't exist, throw the following error
error Error.Record( "Error ID not existing!", "The error ID doesn't exist! Use an existing one!"),
//Throw the custom error
Result = error Error.Record( FilterForCustErrID[reason], FilterForCustErrID[message], FilterForCustErrID[detail] )
in
Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.