Formulas Challenge for 365

%3CLINGO-SUB%20id%3D%22lingo-sub-3299548%22%20slang%3D%22en-US%22%3EFormulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299548%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20for%20reading%20this%20post!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20propose%20a%20formulas%20challenge%20(The%20shorter%20the%20better).%26nbsp%3B%20Attached%20is%20a%20workbook%20in%20need%20of%20two%20formulas.%26nbsp%3B%20I%20have%20solutions%20for%20each%20(Formula%201%20is%2066%20characters%2C%20Formula%202%20is%2072)%20but%20would%20like%20to%20compare%20notes%20with%20others%20and%20maybe%20learn%20some%20new%20things.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFormula%201%3A%20Rollup%20data%20from%205%20sheets.%26nbsp%3B%20Must%20be%20sorted%20A-Z%2C%20no%20blank%20rows%2C%20and%20must%20include%20header.%3C%2FP%3E%3CP%3EFormula%202%3A%20Find%20the%20j%2B%20max%20for%20each%20agent.%26nbsp%3B%20This%20sounds%20simple%20but%20you'll%20have%20to%20see%20the%20workbook.%26nbsp%3B%20The%20arrangement%20is%20based%20off%20a%20client's%20workbook%20that%20crossed%20my%20desk%20several%20years%20ago.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20rules%20are%20simple.%20%3CSTRONG%3EFor%20this%20challenge%20the%20following%20are%20restricted%3A%20vba%2C%20PowerQuery%2C%20fill%20handle%2C%20use%20of%20named%20items%2C%20and%20alteration%20of%20existing%20data.%26nbsp%3B%20Functions%20available%20on%20the%20Beta%20channel%20are%20fair%20game.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EYou%20may%20find%20this%20exercise%20difficult%20if%20you're%20not%20on%20365%20with%20Insider.%26nbsp%3B%20The%20goal%20of%20this%20exercise%20is%20to%20explore%20some%20of%20the%20newest%20functions%20Excel%20has%20to%20offer.%20Have%20at%20it!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3299548%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301870%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301870%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3BI%20am%20not%20happy%20with%20the%20array%20of%20array%20limitations%20but%20Thunks%20can%20be%20used%20to%20overcome%20the%20problem%20in%20many%20instances.%26nbsp%3B%20The%20attached%20workbook%20contains%20a%20Lambda%20function%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20Expand%CE%BB(array%CF%91)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ewhich%20turns%20a%20column%20of%20row-thunks%20back%20into%20a%202D%20array.%26nbsp%3B%20I%20would%20far%20prefer%20such%20tricks%20were%20not%20necessary%20but%20it%20is%20something%20I%20have%20been%20bitching%20about%20for%20years%20(along%20with%20array%20breakup%20that%20is%20now%20solved%20by%20Lambda%20helper%20functions).%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3EExpand%CE%BB%20%3D%20LAMBDA(%CF%91%2C%0A%20%20%20%20LET(%0A%20%20%20%20%20%20%20%20n%E2%82%81%2C%20ROWS(%CF%91)%2C%0A%20%20%20%20%20%20%20%20n%E2%82%82%2C%20MAX(MAP(%CF%91%2CColumns%CE%BB))%2C%0A%20%20%20%20%20%20%20%20MAKEARRAY(n%E2%82%81%2Cn%E2%82%82%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20LAMBDA(i%E2%82%81%2Ci%E2%82%82%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20INDEX(INDEX(%CF%91%2Ci%E2%82%81%2C1)()%2Ci%E2%82%82)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A)%3B%0A%0AColumns%CE%BB%20%3D%20LAMBDA(x%CF%91%2CCOLUMNS(x%CF%91()))%3B%0A%0AThunk%CE%BB%20%3D%20LAMBDA(x%2C%20LAMBDA(x))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Feusprig.org%2Farxiv%2FBartholomew%2520EuSpRIG%25202019.pdf%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EMicrosoft%20Word%20-%20Will%20modern%20Excel%20finally%20change%20the%20way%20Models%20are%20built%20v2.0.docx%20(eusprig.org)%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20it%20is%20any%20use%20to%20you%2C%20I%20could%20also%20offer%20Lambda%20functions%20that%20read%20multidimensional%20data%20from%20an%20arbitrary%20cross-tab%20dataset%20(I%20have%20only%20gone%20to%204D%20but%20there%20is%20no%20reason%20why%20it%20should%20not%20be%20applied%20to%20higher%20dimensional%20data%20were%20that%20relevant).%26nbsp%3B%20The%20second%20Lambda%20function%20uses%20the%20first%20and%20generates%20a%20normalised%20dataset%20or%20will%20generate%20any%20of%20the%20normal%20pivot%20table%20crosstabs.%26nbsp%3B%20It%20is%20also%20possible%20to%20aggregate%20a%20column%20by%20addition.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301623%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301623%22%20slang%3D%22en-US%22%3EAdmittedly%2C%20the%20shortest%20formula%20approach%20may%20not%20be%20the%20best%20if%20taking%20into%20account%20sustainability%20and%20being%20able%20to%20use%20the%20formula%20in%20more%20workbooks.%20I've%20been%20looking%20for%20situations%20to%20create%20universal%20LAMBDAs%20that%20I%20can%20use%20again%20and%20again.%20I've%20gone%20back%20to%20some%20old%20vba%20exercises%20to%20see%20if%20I%20could%20make%20LAMBDAs%20do%20the%20same%20thing%20as%20vba.%20I've%20run%20into%20the%20dreaded%20'array%20of%20arrays'%20limitation%20(TEXTSPLIT%2C%20naturally)%20when%20trying%20to%20write%20a%20LAMBDA%20to%20un-pivot%20some%20data.%20I%20believe%20it's%20possible%20with%20INDEX%20(and%20maybe%20OFFSET)%20but%20not%20worth%20the%20trouble%20if%20PowerQuery%20can%20do%20it%20in%20a%20snap.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299871%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299871%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%22VSTACK%20...%20support%203D%20references.%20Very%20cool.%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EYes%2C%20that%20was%20quite%20a%20discovery.%26nbsp%3B%20Stay%20in%20touch%20over%20the%20results%20of%20further%20exploration.%26nbsp%3B%20Although%20this%20forum%20is%20largely%20devoted%20to%20Q%26amp%3BA%2C%20I%20would%20like%20to%20see%20more%20discussion%20and%20sharing%20of%20experience.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EYou%20can%20see%20from%20my%20response%20that%20I%20am%20not%20fully%20committed%20to%20the%20shortest%20formula%20concept%2C%20including%2044%20spaces%20and%206%20line%20feeds%20in%20a%20formula%20of%20length%20123%20definitely%20rates%20a%20'could%20do%20better'!%26nbsp%3B%20I%20have%20also%20used%20thunks%20in%20the%20Max%20problem%20as%20a%20device%20for%20getting%202%20row%20arrays%20through%20MAP.%26nbsp%3B%20The%20more%20obvious%20BYROW%20does%20not%20allow%20multiple%20parameters.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20final%20version%20of%20you%20Max%20problem%20is%20more%20comfortable%20for%20me%20because%20I%20am%20used%20to%20picking%20out%20arrays%20from%20multidimensional%20layouts.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAs%20for%20your%20comment%20regarding%20VBA%2C%20last%20week%20on%20another%20forum%2C%20I%20wrote%20a%20formula%20which%20turned%20out%20to%20be%20needed%20because%20an%20add-in%20had%20ceased%20to%20work.%26nbsp%3B%20The%20places%20where%20I%20would%20still%20need%20VBA%20include%20writing%20event%20handlers%20or%20using%20the%20object%20model%20to%20interrogate%20relationships%20between%20shape%20objects.%26nbsp%3B%20Most%20calculation%20would%20appear%20to%20be%20better%20achieved%20through%20the%20use%20of%20worksheet%20formulae.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299778%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299778%22%20slang%3D%22en-US%22%3EThis%20is%20a%20fascinating%20approach!%20Thank%20you%20for%20sharing.%20With%20access%20to%20all%20these%20functions%2C%20this%20is%20essentially%20vba%20at%20the%20sheet%20level%20but%20much%20more%20accessible%20(DROP%2FTAKE%20are%20the%20equivalents%20to%20.resize%2C%20etc.).%20I%20was%20testing%20VSTACK%20the%20other%20day%20and%20was%20surprised%20to%20see%20it%20(and%20HSTACK)%20support%203D%20references.%20Very%20cool.%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20page%20will%20have%20to%20be%20updated%20soon%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fcreate-a-3-d-reference-to-the-same-cell-range-on-multiple-worksheets-40ca91ff-9dcb-4ad1-99d2-787d0bc888b6%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fcreate-a-3-d-reference-to-the-same-cell-range-on-multiple-worksheets-40ca91ff-9dcb-4ad1-99d2-787d0bc888b6%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299755%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299755%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20re-attaching%20%232.%26nbsp%3B%20After%20some%20thought%2C%20I%20recall%20the%20client's%20data%20was%20much%20%22worse%22.%26nbsp%3B%20It%20was%20arranged%20as%20such%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Patrick2788_0-1651410967901.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F368290i0748BF85639263BD%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Patrick2788_0-1651410967901.png%22%20alt%3D%22Patrick2788_0-1651410967901.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299691%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299691%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attempted%20part%201%20of%20your%20challenge%20but%20not%20within%20the%20rules.%26nbsp%3B%20I%20only%20use%20defined%20names%20to%20reference%20data%20(at%20one%20time%20I%20ran%20macros%20to%20delete%20the%20content%20of%20any%20cell%20that%20contained%20a%20direct%20reference1).%3C%2FP%3E%3CP%3EMy%20approach%20was%20to%20create%20an%20array%20of%20Thunks%2C%20each%20element%20containing%20the%20data%20from%20one%20of%20the%20tables.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20submitting%2C%20I%20have%20had%20a%20look%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B's%20solution%20and%20may%20have%20some%20reconsidering%20to%20do.%26nbsp%3B%20I%20had%20not%20realised%20that%20VSTACK%20works%20over%20a%203D%20range%20reference!%26nbsp%3B%20It%20does%20mean%20that%20the%20tables%20have%20to%20be%20aligned%20but%20often%20they%20are.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299690%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299690%22%20slang%3D%22en-US%22%3EI%20used%20DROP%20and%20UNIQUE%20to%20take%20care%20of%20the%20blank.%3CBR%20%2F%3E%3CBR%20%2F%3E%3DVSTACK('1'!A1%3AB1%2CDROP(SORT(UNIQUE(VSTACK('1%3A5'!A1%3AB30))%2C1%2C1)%2C-1))%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299667%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299667%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3BA%20short%20formula%20isn't%20always%20best%20%3A))%3C%2FP%3E%3CP%3EFor%20number%201%20I%20could%20come%20up%20with%20this%20(at%2072%20char)%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DVSTACK('1'!A1%3AB1%2CTAKE(SORT(VSTACK('1%3A5'!A2%3AB30))%2CCOUNTA('1%3A5'!A2%3AA30)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20feel%20that%20there%20must%20be%20a%20better%20way%20to%20exclude%20the%20blanks%20asThe%20COUNTA%20at%20the%20end%20looks%20a%20bit%20clumsy.%20And%20if%20you%20hadn't%20insisted%20on%20a%20formula%20generated%20header%2C%20the%20count%20would%20have%20come%20down%20to%2054%20chars.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299649%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299649%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3BFormula%202%20(57%20characters)%20could%20be%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DIFERROR(BYROW(B2%3AJ16*(B1%3AJ15%3D%22j%2B%22)%2CLAMBDA(a%2CMAX(a)))%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202022-05-01%20at%2007.33.12.png%22%20style%3D%22width%3A%20415px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F368262i9AA4E5767822626A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%202022-05-01%20at%2007.33.12.png%22%20alt%3D%22Screenshot%202022-05-01%20at%2007.33.12.png%22%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299585%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299585%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1639%22%20target%3D%22_blank%22%3E%40Detlef%20Lewin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20check%20the%20directions%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299571%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299571%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20thought%20the%20formula%20is%20obvious.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DMAXIFS(B2%3AJ2%2CB1%3AJ1%2C%22j%2B%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299564%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299564%22%20slang%3D%22en-US%22%3EPlease%20share%20your%20formula.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299563%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299563%22%20slang%3D%22en-US%22%3EI%20get%20the%20expected%20results.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299559%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299559%22%20slang%3D%22en-US%22%3EAre%20you%20able%20to%20use%20it%20to%20find%20the%20j%2B%20max%20for%20each%20agent%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299551%22%20slang%3D%22en-US%22%3ERe%3A%20Formulas%20Challenge%20for%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299551%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428790%22%20target%3D%22_blank%22%3E%40Patrick2788%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFormula%202%20is%20a%20simple%20MAXIFS().%20Which%20is%2027%20characters%20long%20(in%20de-version%20of%20Excel).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Super Contributor

Thank you for reading this post!

 

I propose a formulas challenge (The shorter the better).  Attached is a workbook in need of two formulas.  I have solutions for each (Formula 1 is 66 characters, Formula 2 is 72) but would like to compare notes with others and maybe learn some new things.

 

Formula 1: Rollup data from 5 sheets.  Must be sorted A-Z, no blank rows, and must include header.

Formula 2: Find the j+ max for each agent.  This sounds simple but you'll have to see the workbook.  The arrangement is based off a client's workbook that crossed my desk several years ago.

 

The rules are simple. For this challenge the following are restricted: vba, PowerQuery, fill handle, use of named items, and alteration of existing data.  Functions available on the Beta channel are fair game.

 

Note:

You may find this exercise difficult if you're not on 365 with Insider.  The goal of this exercise is to explore some of the newest functions Excel has to offer. Have at it!

 

 

15 Replies

@Patrick2788 

Formula 2 is a simple MAXIFS(). Which is 27 characters long (in de-version of Excel).

 

Are you able to use it to find the j+ max for each agent?
I get the expected results.
Please share your formula.

@Patrick2788 

I thought the formula is obvious.

=MAXIFS(B2:J2,B1:J1,"j+")

 

@Detlef Lewin 

Please check the directions again.

@Patrick2788 Formula 2 (57 characters) could be:

=IFERROR(BYROW(B2:J16*(B1:J15="j+"),LAMBDA(a,MAX(a))),"")

Screenshot 2022-05-01 at 07.33.12.png 

@Patrick2788 A short formula isn't always best :))

For number 1 I could come up with this (at 72 char):

=VSTACK('1'!A1:B1,TAKE(SORT(VSTACK('1:5'!A2:B30)),COUNTA('1:5'!A2:A30)))

I feel that there must be a better way to exclude the blanks asThe COUNTA at the end looks a bit clumsy. And if you hadn't insisted on a formula generated header, the count would have come down to 54 chars.

I used DROP and UNIQUE to take care of the blank.

=VSTACK('1'!A1:B1,DROP(SORT(UNIQUE(VSTACK('1:5'!A1:B30)),1,1),-1))

@Patrick2788 

I have attempted part 1 of your challenge but not within the rules.  I only use defined names to reference data (at one time I ran macros to delete the content of any cell that contained a direct reference1).

My approach was to create an array of Thunks, each element containing the data from one of the tables.

 

Since submitting, I have had a look at @Riny_van_Eekelen 's solution and may have some reconsidering to do.  I had not realised that VSTACK works over a 3D range reference!  It does mean that the tables have to be aligned but often they are.

@Patrick2788 

I'm re-attaching #2.  After some thought, I recall the client's data was much "worse".  It was arranged as such:

Patrick2788_0-1651410967901.png

 

This is a fascinating approach! Thank you for sharing. With access to all these functions, this is essentially vba at the sheet level but much more accessible (DROP/TAKE are the equivalents to .resize, etc.). I was testing VSTACK the other day and was surprised to see it (and HSTACK) support 3D references. Very cool.

This page will have to be updated soon:
https://support.microsoft.com/en-us/office/create-a-3-d-reference-to-the-same-cell-range-on-multiple...

@Patrick2788 

"VSTACK ... support 3D references. Very cool."

Yes, that was quite a discovery.  Stay in touch over the results of further exploration.  Although this forum is largely devoted to Q&A, I would like to see more discussion and sharing of experience.

 

You can see from my response that I am not fully committed to the shortest formula concept, including 44 spaces and 6 line feeds in a formula of length 123 definitely rates a 'could do better'!  I have also used thunks in the Max problem as a device for getting 2 row arrays through MAP.  The more obvious BYROW does not allow multiple parameters.

 

The final version of you Max problem is more comfortable for me because I am used to picking out arrays from multidimensional layouts.

 

As for your comment regarding VBA, last week on another forum, I wrote a formula which turned out to be needed because an add-in had ceased to work.  The places where I would still need VBA include writing event handlers or using the object model to interrogate relationships between shape objects.  Most calculation would appear to be better achieved through the use of worksheet formulae.

 

 

 

 

Admittedly, the shortest formula approach may not be the best if taking into account sustainability and being able to use the formula in more workbooks. I've been looking for situations to create universal LAMBDAs that I can use again and again. I've gone back to some old vba exercises to see if I could make LAMBDAs do the same thing as vba. I've run into the dreaded 'array of arrays' limitation (TEXTSPLIT, naturally) when trying to write a LAMBDA to un-pivot some data. I believe it's possible with INDEX (and maybe OFFSET) but not worth the trouble if PowerQuery can do it in a snap.

@Patrick2788 I am not happy with the array of array limitations but Thunks can be used to overcome the problem in many instances.  The attached workbook contains a Lambda function 

= Expandλ(arrayϑ)

which turns a column of row-thunks back into a 2D array.  I would far prefer such tricks were not necessary but it is something I have been bitching about for years (along with array breakup that is now solved by Lambda helper functions).

Expandλ = LAMBDA(ϑ,
    LET(
        n₁, ROWS(ϑ),
        n₂, MAX(MAP(ϑ,Columnsλ)),
        MAKEARRAY(n₁,n₂,
            LAMBDA(i₁,i₂,
                INDEX(INDEX(ϑ,i₁,1)(),i₂)
            )
        )
    )
);

Columnsλ = LAMBDA(xϑ,COLUMNS(xϑ()));

Thunkλ = LAMBDA(x, LAMBDA(x));

Microsoft Word - Will modern Excel finally change the way Models are built v2.0.docx (eusprig.org)

 

If it is any use to you, I could also offer Lambda functions that read multidimensional data from an arbitrary cross-tab dataset (I have only gone to 4D but there is no reason why it should not be applied to higher dimensional data were that relevant).  The second Lambda function uses the first and generates a normalised dataset or will generate any of the normal pivot table crosstabs.  It is also possible to aggregate a column by addition.