Forum Discussion
Additional help needed with existing formula using LAMDA- Excel 365
Good day! I received assistance here with this formula. It's supposed to use the scores of various evaluation categories displayed in E5:E12 to only display for printing the records for the ones on which the goal is either "Not Met" or "Exceed". The review categories that are blank (no items reviewed) and/or those indicated as "Met", should not be spilled.
Currently, the formula included below only excludes the category and records of the one where there are no values (no items reviewed). So, I'm trying to figure out how to adjust the formula to also exclude the records of the review categories marked as "Met" in the range E5:E12 on the spilled report tab.
=LET(filterBy, RESULTS!A2:C2,
resultTable, RESULTS!A5:E12,
columnCounts, {5,6,5,5,5,7,6,7},
report, LAMBDA(result_filter,result_row,table_all, LET(table_data, DROP(table_all,1),
table_matches, (CHOOSECOLS(table_data,3)=INDEX(result_filter,1))*
(CHOOSECOLS(table_data,2)>=INDEX(result_filter,2))*
(CHOOSECOLS(table_data,2)<=INDEX(result_filter,3)),
IF(N(INDEX(result_row,2)),
VSTACK("*** "&INDEX(result_row,1)&" ***",
TAKE(table_all,1),
FILTER(table_data, table_matches, "")),
""))),
total, REDUCE("",SEQUENCE(ROWS(resultTable)),LAMBDA(p,q,VSTACK(p,
LET(tbl, INDIRECT("tbl"&TEXTJOIN(,,TEXTSPLIT(INDEX(resultTable,q,1),{" ","-"}))&"[#ALL]"),
report(filterBy, CHOOSEROWS(resultTable,q), CHOOSECOLS(tbl,SEQUENCE(,INDEX(columnCounts,q)),SEQUENCE(,2,COLUMNS(tbl)-1))))
))),
IFNA(IF(total=0, "", total),""))
Any assistance with this is greatly appreciated!
I reorganized the sample file, so each table now contains the same number of columns, in the same order, as the updated SheetMap. The only thing I had to change about the formula (from rev3.0) was the _cId variable to set the field mapping:
=LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,6,5,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,6,,,8,9", "1,2,3,4,,,5,11,12", "1,2,3,4,7,6,5,12,13", "1,2,3,4,6,,5,14,15", "1,2,3,4,6,7,8,14,19"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(val(1)," ",),"-",)&"[#ALL]"), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) )
I also added a 'FieldMap' worksheet to the attached revision, so you can see how the field mapping was generated (there are 4 formulas highlighted in blue, as well as a note showing the formula used as the Data Validation List Source for range C5:U12).
If you're still having issues applying these methods to your master workbook, I'm afraid there's not much more I can do to help aside from gaining access to your actual workbook to troubleshoot the problem.
Best of luck!
17 Replies
- Marcus_BoothIron Contributor
djclements - For some reason, my replies to specific messages aren't posting here. I tried my best to find a problem, but I can't see anything wrong with the references. The only thing that is different on the original compared to the dummy posted here is that the staff names were removed along with all but a few records in each review tab, plus there are some other tabs that were not included that aren't referenced anywhere. Could it be the other tabs? I'm stumped. It works in the one you sent, but not on the original.
- djclementsBronze Contributor
It's not likely to be related to the other tabs/worksheets in your master workbook, as the formula is only referencing cells/ranges in the 'RESULTS' tab directly. The INDIRECT function is being used to reference tables in the workbook, but the syntax for this is the same as what was already working in your original sample workbook(s), so that wouldn't explain it.
I saw your comment on the previous thread, where you confirmed "The master workbook is named differently and contains more tabs than the redacted (included here) spreadsheet, but all of the table names and column headers are the same.", so there shouldn't be any issues when copying the formula over. However, I also noticed there was a bit of a struggle to get any of the suggested formulas on that thread to work, and a considerable amount of time was spent troubleshooting this. To transfer the formula from the sample workbook to your master workbook, highlight the entire formula from within the formula bar in the sample workbook and press Ctrl+C to copy, then select the destination cell in your master workbook, click into the formula bar (delete any previous formula, if applicable) and press Ctrl+V to paste.
#VALUE! errors can be difficult to track down, but it usually means there is an issue with one or more of the data types used. For example, =10+"text" will return this error because the addition operator is expecting two numbers (type 1) but received a text string (type 2). =TAKE(A1:A5,{3}) will also error because the rows argument is expecting a scalar (type 1) but received an array (type 64). I've reviewed my formula and don't see anything out of place. Even if there was, it wouldn't explain why the formula works in the sample workbook but not in the master workbook.
Having said that, I'm not really a fan of how the current "working" formula outputs the report. There's a different number of columns being selected from each table, and the field order is different between tables. The end result is a bit of a mess, where only the first 3 columns are identical across all 8 tables, and the rest are a mix-match of data types. This makes formatting dates virtually impossible, as fields like "Date Processed" and "Date Reconsidered" are appearing in the same columns as numeric fields like "PID" and "Issue Number".
Another option is to use something of a field-mapping table to link compatible fields and output them to the same column. For example:
=LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,5,6,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,5,,,7,8", "1,2,3,4,,,5,11,12", "1,2,3,5,7,6,4,12,13", "1,2,3,4,5,,6,14,15", "1,2,3,4,5,6,7,13,18"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(val(1)," ",),"-",)&"[#ALL]"), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) )
The width of the output array in this example is fixed (9 columns). _cId is where the field-mapping is set for each table, and arr is where the field-mapping is applied (using SORTBY-TEXTSPLIT). This will output numeric fields like "PID" and "Issue Number" in Field5, and all date fields in Field7, making them easier to format:
Furthermore, if you're always dealing with the same 8 tables, it's also possible to eliminate the INDIRECT function by utilizing a custom CHOOSE based lambda function to select each table as needed. For example:
=LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), TBLλ, LAMBDA(table_id,CHOOSE(table_id, tblClaims[#All],tblMiscAssignments[#All],tblProcessProtest[#All],tblIDD[#All], tblProcessAppeal[#All],tblDPU[#All],tblVetRRVDVOP[#All],tblRESEA[#All])), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,5,6,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,5,,,7,8", "1,2,3,4,,,5,11,12", "1,2,3,5,7,6,4,12,13", "1,2,3,4,5,,6,14,15", "1,2,3,4,5,6,7,13,18"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, TBLλ(val(2)), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) )
TBLλ is the lambda function that contains the references to each table, and TBLλ(val(2)) is where each table is recalled (replacing the INDIRECT function). I've also used a custom VALλ function here to make referencing the variables easier (replacing the INDEX function).
Please note, many of the variables and functions used in these examples can be defined in Name Manager, which would make the end formula shorter and easier to write. However, I refrained from doing so to make it as easy as possible for you to transfer the formula to your master workbook. If you're still experiencing issues and want to send me a copy of your master workbook in a private message (go to my profile page and click "Message"), I'll be happy to troubleshoot it for you. Cheers!
- Marcus_BoothIron Contributor
I think I found the problem. I forgot that I had moved one of the columns on the RRV/DVOP table to make the date columns line up better on the REPORT tab. I have now adjusted the SheetMap accordingly. Here is the corrected SheetMap. I'm really sorry about that. Would you mind a final adjustment to the formula that takes this into account? Please let me know if you would need anything else. Thank you!
- djclementsBronze Contributor
Try the following revision and see if it meets your needs:
=LET( _rep, RESULTS!A2, _beg, RESULTS!B2, _end, RESULTS!C2, _inc, (RESULTS!E5:E12="EXCEED")+(RESULTS!E5:E12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( keys, FILTER(HSTACK(RESULTS!A5:A12,VSTACK(5,6,5,5,5,7,6,7)),_inc), cols, MAX(DROP(keys,,1))+2, EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,cols,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), REDUCE( EXPλ("REPORT:"), SEQUENCE(ROWS(keys)), LAMBDA(acc,rId, LET( lbl, INDEX(keys,rId,1), tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(lbl," ",),"-",)&"[#ALL]"), arr, HSTACK(TAKE(tbl,,INDEX(keys,rId,2)),TAKE(tbl,,-2)), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(INDEX(bdy,,3),INDEX(bdy,,2))), VSTACK(acc,EXPλ("["&rId&"] "&lbl&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) )
See attached, if needed...
EDIT: added an optional [rws] argument to the EXPλ function so the qry results can be expanded by 1 row to separate each table in the final output.
- Marcus_BoothIron Contributor
It didn't work. Just returns #VALUE! in the cell. Sorry, but I'm not familiar with what you are using. I can't really point to anything in the formula. Thanks for the try. :)
- djclementsBronze Contributor
The problem is in column E (GOAL) on the RESULTS worksheet in your 082625 stripped-down file. It's not visibly obvious because the results are hidden from view (via conditional formatting) when column D="N/A". If you remove the formatting, you'll see the formulas in column E are returning #VALUE! errors when column D="N/A". Your original 061625 sample file had a different formula in this column that worked properly. Either restore the original formula, or try the following in cell E5 (and copy down):
=IFS(D5="n/a","",D5<F5,"NOT MET",D5>G5,"EXCEED",1,"MET")
Once this is corrected, you should be able to successfully implement ANY of the methods I've suggested thus far. If you need help tweaking anything else thereafter, just let me know.
- m_tarlerBronze Contributor
wow I sort of remember this. lol.
here is the updated function:
=LET(filterBy, RESULTS!A2:C2, resultTable, RESULTS!A5:E12, columnCounts, {5,6,5,5,5,7,6,7}, report, LAMBDA(result_filter,result_row,table_all, LET(table_data, DROP(table_all,1), table_matches, (CHOOSECOLS(table_data,3)=INDEX(result_filter,1))* (CHOOSECOLS(table_data,2)>=INDEX(result_filter,2))* (CHOOSECOLS(table_data,2)<=INDEX(result_filter,3)), IF((TAKE(result_row,,-1)="EXCEED")+(TAKE(result_row,,-1)="NOT MET"), VSTACK("*** "&INDEX(result_row,1)&" ***", TAKE(table_all,1), FILTER(table_data, table_matches, "")), ""))), total, REDUCE("",SEQUENCE(ROWS(resultTable)),LAMBDA(p,q,VSTACK(p, LET(tbl, INDIRECT("tbl"&TEXTJOIN(,,TEXTSPLIT(INDEX(resultTable,q,1),{" ","-"}))&"[#ALL]"), report(filterBy, CHOOSEROWS(resultTable,q), CHOOSECOLS(tbl,SEQUENCE(,INDEX(columnCounts,q)),SEQUENCE(,2,COLUMNS(tbl)-1)))) ))), IFNA(IF(total=0, "", total),""))
on line 8 above it used to just check if column 2 was a number but now checks if that last column is specifically either "EXCEED" or "NOT MET"
hope that helps.
in the attached it is in the 'Results New' tab
- Marcus_BoothIron Contributor
That did the trick for displaying the correct categories. However, each category that does not appear is still producing a certain number of blank lines between and, oddly, after the records for the displayed categories, there are 3 lines with !Value# errors in them. Not sure what that's about, but is there a way to fix so that only one blank line appears between the categories to separate them?