I have a Google Sheets table with a custom function. I have made a sanitized and reduced version of it here:
Google Sheet with Custom Function (CF)
The more rows I have in one tab, the more often I get the error:
"Error Internal error while executing the custom function."
Doing some research helped me to come to the conclusion that this issue is probably because the custom function is not used as a range formula as it is suggested here:
The custom function looks something like this:
function fifo(datesA, assetQtysA, transVolumesA, minHoldTime) {
//console.log("Original values: " + createCM({datesA, assetQtysA, transVolumesA, minHoldTime}));
var dates = [];
dates = Array.isArray(datesA) ? datesA : [datesA];
var assetQtys = [];
assetQtys = Array.isArray(assetQtysA) ? assetQtysA : [assetQtysA];
var transVolumes = [];
transVolumes = Array.isArray(transVolumesA) ? transVolumesA : [transVolumesA];
if (transVolumes.length === 0 || assetQtys.length === 0 || dates.length === 0) {
throw new Error('The transaction volumes, the asset quantities and the dates must each have at least one element!');
}
if (transVolumes.length !== assetQtys.length || transVolumes.length !== dates.length) {
throw new Error('The total transaction values, the asset quantities and dates must have the same amount of elements!');
}
if (assetQtys[0] < 0) {
throw new Error('The first transaction needs be a BUY transaction.');
}
//Something happening here ;-)
return [return_1, return_2, return_3, return_4, return_5, return_6];
Sorry, I'm not comfortable sharing the entire source code. But I hope you are able to understand.
So I'm trying to apply the range strategy (from the link above) on my special case, but have failed so far.
I have tried to apply this to the code, but I can't find my way out of multiple errors. I guess I'm on the wrong path here.
Anyone know how to manage this? At least I hope after applying the range strategy the internal error message will disappear.
Many thanks for your help.