Put simply, this formula …
=LET(
COMMENT1, " --- The following formulas are used for initialisation purposes and set the scene for the remaining calculations ---",
_dataMatrix, LSLCalculation[[#All],[VarianceWithAccrualBankWeeks]:[VarianceWithOSWBankHours]],
_dataMatrixWoHeaders, DROP(_dataMatrix, 1),
COMMENT2, " --- We now need to select the datasets so we can unpivot the data by date, by variance group (i.e. pay code) ---",
_allDates, B1 + SEQUENCE(B2, 1, 0, 1),
_varianceGroups, TRANSPOSE(CHOOSEROWS(_dataMatrix, 1)),
_numberOfExplodedRows, COUNTA(_allDates) * COUNTA(_varianceGroups),
COMMENT3, " --- This is where we start building out each column for the resulting data set ---",
COMMENT4, " --- Firstly, build up the unpivoted references by row and column for each resulting record ---",
_allRowsByWorkDate, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, MOD(r - 1, COUNTA(_allDates)) + 1)),
_allRowsByVarianceColumns, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, ROUNDUP(r / COUNTA(_allDates), 0))),
_allRowsByLookupMatrix, HSTACK(_allRowsByWorkDate, _allRowsByVarianceColumns),
_allRowsByLookupMatrix)
… produces an incorrect output compared to Excel.
Further back in the logic, the COUNTA()
formula was originally using ROWS()
to count the number of rows in the array but that would only return the first character of the result, i.e. should be 1092 but returned 1, should be 6459 but returned 6, etc. ROWS()
does work in isolation or in a simple context.
It all seems to fall apart when using MAKEARRAY
and am keen to know if I should expect the calculation engine to be able to deal with it. It simply does not return the correct result. It’s not far off though.
I have a workbook I can share which can be used to debug the issue.
WFS Output Formula (Split Out).zip (682.2 KB)