Description
I have a script that pulls data from a mongo database, and then creates 13 different sheets in an excel file based on the pulled data.
The script was functioning correctly up until I added a single new function:
//adding formula for 'Sessions (Filtered)' worksheet.getCell('O1').value = { formula: "LET(a,B2:B"+lastRow+",b,BYROW(a,LAMBDA(r,AGGREGATE(3,5,r))),COUNTA(UNIQUE(FILTER(a,b=1))))" };
Now when I run the script, it succeeds, but when I try to open the excel file I get a pop-up "We found a problem with some content in 'filename.xlsx'. do you want us to try too recover as much as we can?"
Accepting shows everything, but the new function is absent from the generated sheets.
The formula is intended to sum the number of unique ID's in column B for visible rows only (subtotal doesn't work for a returned array unfortunately, so it looks very messy). lastRow is just a string I add so that the function is applied across all rows. I am using it successfully in the same manner in the non sheet-breaking functions as well.
I have already tried testing this function in excel itself, and it works perfectly.
These are the other functions that I was using before adding the new sheet-breaking function:
//adding formula for 'Total Collected' worksheet.getCell('K1').value = { formula: "SUBTOTAL(109,G2:G"+lastRow+")" };
//adding formula for 'Remaining Balance' worksheet.getCell('M1').value = { formula: "SUBTOTAL(109,H2:H"+lastRow+")" };
Can anyone tell me what might be happening here? Thanks in advance!