Sorry to be throwing all of this at you but if I extend on the formula again (because what I’ve given you thus far is not the entire outcome) then I get another issue.
Not sure why but I’m getting #NAME? on this formula …
=LET(
COMMENT1, " --- The following formulas are used for initialisation purposes and set the scene for the remaining calculations ---",
_startDate, DATEVALUE(XLOOKUP("ExecutionDate",CurrentPersonAndWorkDetails[Key],CurrentPersonAndWorkDetails[Value],,0,-1)),
_daysOut, DATEDIF(_startDate, MAX(LSLCalculation[Date]), "d") + 1,
_employeeID, XLOOKUP("EmployeeID",CurrentPersonAndWorkDetails[Key],CurrentPersonAndWorkDetails[Value],,0,1),
_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, _startDate + SEQUENCE(_daysOut, 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, INDEX(_allDates, MOD(r - 1, COUNTA(_allDates)) + 1))),
_allRowsByVarianceColumns, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, CHOOSEROWS(_varianceGroups, ROUNDUP(r / COUNTA(_allDates), 0)))),
_allRowsByLookupMatrix, HSTACK(_allRowsByWorkDate, _allRowsByVarianceColumns),
_allRowsByLookupMatrixRC, MAKEARRAY(_numberOfExplodedRows, 2, LAMBDA(r,c, IF(c = 1, MATCH(INDEX(_allRowsByLookupMatrix, r, 1), LSLCalculation[Date], 0), MATCH(INDEX(_allRowsByLookupMatrix, r, 2), _varianceGroups, 0)))),
COMMENT5, " --- Build out each column and then HSTACK them all up to produce the file structure for OFlow ---",
_allRowsByBlankCell, IF(SEQUENCE(_numberOfExplodedRows, 1), ""),
_allRowsByEmployeeID, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, _employeeID)),
_allRowsHoursLookup, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, INDEX(_dataMatrixWoHeaders, INDEX(_allRowsByLookupMatrixRC, r, 1), INDEX(_allRowsByLookupMatrixRC, r, 2)))),
_allRowsByPayCodes, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, XLOOKUP(CHOOSEROWS(_varianceGroups, ROUNDUP(r / COUNTA(_allDates), 0)), VarianceToAdjPayCodeLookup[VarianceColumnName], VarianceToAdjPayCodeLookup[AssociatedPayCode]))),
_unfilteredResult, HSTACK(_allRowsByEmployeeID, _allRowsByWorkDate, _allRowsByPayCodes, _allRowsByBlankCell, _allRowsByBlankCell, _allRowsHoursLookup),
COMMENT6, " --- Filter the result to remove any rows where the variance is 0 ---",
_result, FILTER(_unfilteredResult, ABS(INDEX(_unfilteredResult,, 6)) >= 0.000001),
_allRowsHoursLookup)
… that (at this stage) is the entire formula that will generate the outcome I am after.
This row …
_allRowsHoursLookup, MAKEARRAY(_numberOfExplodedRows, 1, LAMBDA(r,c, INDEX(_dataMatrixWoHeaders, INDEX(_allRowsByLookupMatrixRC, r, 1), INDEX(_allRowsByLookupMatrixRC, r, 2))))
… is the one giving me grief. Eventually, I need to get down to the point where _result
is the final variable being returned from the LET() function.