SOLVED

Product of numbers in a row in a dynamic array

%3CLINGO-SUB%20id%3D%22lingo-sub-2836366%22%20slang%3D%22en-US%22%3EProduct%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2836366%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20does%20one%20do%20row-by-row%20evaluations%20with%20a%202d%20dynamic%20array%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20need%20the%20product%20of%20all%20the%20numbers%20in%20each%20row%20in%20an%20array.%20I%20can%20only%20seem%20to%20find%20ways%20to%20get%20the%20product%20of%20all%20the%20numbers%20in%20all%20rows%20of%20the%20array%2C%20reduced%20to%20a%20single%20number.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20spilled%20array%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E0%202%202%3C%2FP%3E%3CP%3E2%201%201%3C%2FP%3E%3CP%3E3%203%202%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EResult%20sought%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E0%3C%2FP%3E%3CP%3E2%3C%2FP%3E%3CP%3E18%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Efrom%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E0*2*2%3C%2FP%3E%3CP%3E2*1*1%3C%2FP%3E%3CP%3E3*3*2%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20struggled%20mightily%20and%20I'm%20about%20to%20resort%20to%20some%20very%20ugly%20text%20manipulation%20plus%20a%20name%20with%20evaluate%20based%20on%20the%20fact%20that%20I%20know%20my%20numbers%20will%20all%20be%20single%20digits%20%3CLI-EMOJI%20id%3D%22lia_disappointed-face%22%20title%3D%22%3Adisappointed_face%3A%22%3E%3C%2FLI-EMOJI%3E%20I%20really%20do%20not%20want%20to%20do%20this!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DLET(%3CBR%20%2F%3E%26nbsp%3Brows%2C%20ROW(array)-ROW(INDEX(array%2C1%2C1))%2C%3CBR%20%2F%3E%26nbsp%3Bwidth%2C%20COLUMNS(array)%2C%3CBR%20%2F%3E%26nbsp%3Bastext%2C%20TEXTJOIN(%22*%22%2C%2Carray)%26amp%3B%22*%22%2C%3CBR%20%2F%3E%26nbsp%3BMID(astext%2Crows*width*2%2B1%2Cwidth*2-1)%3C%2FP%3E%3CP%3E)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20absurd%20that%20I%20can%20make%20four%20rows%20of%20text%2C%20but%20not%20fours%20rows%20of%20results.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20any%20insights.%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-LABS%20id%3D%22lingo-labs-2836366%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2837276%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2837276%22%20slang%3D%22en-US%22%3EYou%20probably%20need%20the%20new%20BYROW%20function%3A%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fbyrow-function-2e04c677-78c8-4e6b-8c10-a4602f2602bb%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fbyrow-function-2e04c677-78c8-4e6b-8c10-a4602f2602bb%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2837438%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2837438%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20something%20I%20have%20been%20complaining%20about%20for%20a%20couple%20of%20years%20or%20so%20now%20but%2C%20as%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3Bsays%2C%20the%20definitive%20solution%20is%20to%20be%20found%20in%20the%20Insiders%20beta%20Channel.%26nbsp%3B%20BYROW%20will%20return%20each%20row%20as%20a%20distinct%20range%20reference%20and%20supports%20any%20relevant%20calculation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20an%20interim%20workaround%2C%20the%20multiplication%20of%20positive%20numbers%20may%20be%20performed%20by%20using%20logarithms%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20EXP(%0A%20%20%20%20MMULT(LN(array%23)%2C%20%7B1%3B1%3B1%7D)%0A%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2837740%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2837740%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3BA%20Secong%20solution%20could%20be%20to%20get%20each%20dynamic%20columns%20using%20Index%2C%20and%20multiply%20them%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DINDEX(H4%23%3BSEQUENCE(ROWS(H4%23))%3B1)*INDEX(H4%23%3BSEQUENCE(ROWS(H4%23))%3B2)*INDEX(H4%23%3BSEQUENCE(ROWS(H4%23))%3B3)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2FGeir%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2838178%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2838178%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20so%20much%20for%20this%20workaround!%20I%20don't%20have%20access%20to%20the%20BYROW%20function%20yet%2C%20but%20your%20solution%20definitely%20works%20for%20my%20use%20case%20for%20now.%20My%20column%20count%20is%20dynamic%20so%20I've%20made%20your%20formula%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3DEXP(MMULT(LN(array%23)%2CTRANSPOSE(SEQUENCE(1%2CCOLUMNS(array%23)%2C1%2C0))))%3CBR%20%2F%3E%3CBR%20%2F%3EMuch%20appreciated!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2838202%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2838202%22%20slang%3D%22en-US%22%3EGeir%2C%20thanks%20so%20much%20-%20my%20problem%20includes%20a%20dynamic%20number%20of%20columns.%20I%20don't%20fully%20grasp%20yet%20how%20Excel%20%22views%22%20an%20array%2C%20but%20I%20was%20surprised%20that%20you%20don't%20seem%20to%20be%20able%20to%20use%20an%20array%20for%20the%20row%2Fcolumn%20parameters%20of%20INDEX.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2839347%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2839347%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20sure%20what%20you%20have%20in%20mind%20for%20this%20reply%20to%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9195%22%20target%3D%22_blank%22%3E%40Geir%20Hogstad%3C%2FA%3E.%26nbsp%3B%20%26nbsp%3BINDEX%20will%20accept%20array%20and%20lift%20the%20appropriate%20scalar%26nbsp%3Bparameters%2C%26nbsp%3B%20For%20example%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20INDEX(array%23%2C%20%7B2%3B5%3B3%7D%2C%20%7B4%2C2%2C5%7D)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewould%20assemble%20a%203x3%20array%20from%20a%20larger%20array.%26nbsp%3B%20It%20would%20still%20have%20the%20same%20problem%20as%20the%20original%2C%3C%2FP%3E%3CP%3E%3CEM%3Ei.e.%3C%2FEM%3E%26nbsp%3Bfunctions%20like%20PRODUCT%20would%20still%20aggregate%20the%20entire%20array%2C%20giving%20a%20single%20value.%26nbsp%3B%20For%20row%20products%2C%20you%20would%20still%20need%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20BYROW(%20%0A%20%20%20%20INDEX(array%23%2C%20%7B2%3B5%3B3%7D%2C%20%7B4%2C2%2C5%7D)%2C%0A%20%20%20%20LAMBDA(row%2C%20PRODUCT(row))%0A%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20just%20puzzled%2C%20not%20critical.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2839408%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2839408%22%20slang%3D%22en-US%22%3E%3CP%3EPeter%2C%20I%20really%20appreciate%20you%20taking%20the%20time%20to%20look%20at%20this.%20I%20may%20have%20expressed%20my%20observation%20incorrectly%20or%20inartfully.%20Here's%20an%20example%20of%20what%20I%20mean%3A%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20A1%2C%20put%20%3DSEQUENCE(5%2C5)%3CBR%20%2F%3EIn%20A7%2C%20put%20%3DROW(A1%23)-ROW(A1)%2B1%3CBR%20%2F%3EIn%20B7%2C%20put%20%3DINDEX(A1%23%2CA7%23%2C0)%3CBR%20%2F%3EIn%20H7%2C%20put%20%3DINDEX(A1%23%2CA7%2C0)%3CBR%20%2F%3E%3CBR%20%2F%3EI%20don't%20understand%20why%20B7%20doesn't%20produce%20full%20rows%20(array%20as%20parameter%20to%20INDEX)%20but%20H7%20does%20(non-array%20as%20parameter%20to%20INDEX).%20I%20expected%20B7%20to%20produce%20a%20row%2C%20and%20I%20also%20expected%20to%20be%20able%20to%20write%20PRODUCT(INDEX(A1%23%2CA7%23%2C0))%20to%20get%20my%20row%20product%20-%20but%20that%20not%20only%20doesn't%20work%2C%20it%20reduces%20to%20a%20single%20result%20for%20the%20whole%20A1%23%20range.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2839817%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2839817%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20you%20get%20from%20Microsoft%20is%20that%20Excel%20never%20has%20handled%20'arrays%20of%20arrays'%20or%20'arrays%20of%20ranges'%20and%20they%20need%20to%20maintain%20backward%20compatibility.%26nbsp%3B%20Now%2C%20however%2C%20it%20has%20become%20important%20because%2C%20with%20dynamic%20arrays%2C%20one%20keeps%20hitting%20the%20problem.%26nbsp%3B%20Your%20formula%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DINDEX(A1%23%2CA7%2C0)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturns%20a%20range%20object%3B%20by%20that%2C%20%3CSTRONG%3ECOLUMN%3C%2FSTRONG%3E%20would%20return%20sheet%20column%20numbers%20and%20%3CSTRONG%3EISREF%3C%2FSTRONG%3E%20would%20return%20TRUE.%26nbsp%3B%20As%20soon%20as%20you%20add%20the%20%23%20to%20A7%2C%20Excel%20recognises%20that%20you%20want%20an%20array%20of%20ranges%20and%20blocks%20the%20calculation%2C%20instead%20returning%20an%20array%20of%20single%20values%20(it%20is%20not%20a%20range).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAs%20for%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DPRODUCT(INDEX(A1%23%2CA7%23%2C0))%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ethat%20just%20suggests%20that%20Excel%20knew%20perfectly%20well%20what%20you%20wanted%20all%20along%2C%20but%20refused%20to%20give%20it%20to%20you!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EEven%20with%20the%20helper%20functions%20%3CSTRONG%3EMAKEARRAY%3C%2FSTRONG%3E%20%3CEM%3Eetc%3C%2FEM%3E.%2C%20it%20can%20be%20difficult%20to%20return%20arrays%20of%20arrays.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2840278%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2840278%22%20slang%3D%22en-US%22%3EHa%20yes%20Excel%20reminds%20me%20of%20other%20relationships%20I%20have%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3E%3CBR%20%2F%3EI%20wanted%20to%20ask%20for%20your%20thoughts%20on%20one%20issue%20with%20the%20workaround%20formula%20you%20gave%20me.%20It%20doesn't%20work%20if%20there%20is%20a%200%20in%20the%20array%20because%20ln(0)%20is%20an%20error.%20Is%20there%20a%20way%20to%20get%20that%20to%20work%3F%20I%20need%20the%200%20result%20of%20the%20product%20as%20it%20has%20a%20semantic%20meaning.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2841370%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2841370%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22...%20other%20relationships%20...%22%20big%20grin!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20solution%20depends%20upon%20the%20semantic%20meaning.%26nbsp%3B%20Taking%20it%20as%20zero%2C%20rather%20than%20omitted%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20LET(%0A%20%20selectedValues%2C%20FILTER(values%2CTabell1%5BOption%5D%3Dselected)%2C%0A%20%20ones%2C%20SEQUENCE(COLUMNS(selectedValues)%2C%2C%2C0)%2C%0A%20%20logs%2C%20LN(ABS(selectedValues))%2C%0A%20%20zeroTest%2C%20ISERROR(logs)%2C%0A%20%20arr%2C%20IF(zeroTest%2C%200%2C%20logs)%2C%0A%20%20result%2C%20MMULT(arr%2C%20ones)%2C%0A%20%20isZero%2C%20MMULT(SIGN(zeroTest)%2C%20ones)%2C%0A%20%20IF(isZero%2C%200%2C%20EXP(result)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EOnce%20you%20have%20Lambda%20functions%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20LET(%0A%20%20PRODUCT%CE%BB%2C%20LAMBDA(row%2C%20PRODUCT(row))%2C%0A%20%20BYROW(array%23%2C%20PRODUCT%CE%BB))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ewould%20be%20preferable.%26nbsp%3B%20An%20interesting%20features%20of%20these%20solutions%20is%20that%20neither%20looks%20remotely%20similar%20to%20a%20traditional%20spreadsheet%20formula.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2842737%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2842737%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3BI%20can't%20quite%20match%2Ffigure%20out%20how%20to%20match%20your%20suggestion%20to%20my%20structure.%20(This%20is%20a%20lot%20of%20hoops%20to%20get%20through%20given%20that%20ByRow%20is%20coming!%20But%20I%20don't%20have%20access%20to%20it.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20what's%20really%20happening.%20I%20have%20a%20list%20of%20donors%20who%20will%20give%20to%20any%20of%20a%20list%20of%20nonprofits%20if%20certain%20criteria%20match%20between%20the%20donor's%20rules%20and%20criteria%20about%20the%20nonprofit.%20Each%20donor%20specifies%20criteria%20the%20she%20excludes%20or%20allows.%20For%20example%2C%20%22allow%20North%20Texas%2C%20exclude%20Oklahoma%2C%20allow%20women's%20causes%2C%20exclude%20animal%20causes%2C%20allow%20this%20nonprofit%2C%20exclude%20that%20nonprofit.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20pick%20a%20particular%20nonprofit%2C%20look%20up%20all%20its%20criteria%2C%20match%20it%20to%20the%20allow%2Fexclude%20rules%20for%20the%20donors%2C%20and%20a%20complicated%20formula%20creates%20an%20array%20that%20looks%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bcriteria1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bcriteria2%26nbsp%3B%20%26nbsp%3B%20criteria3%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bexclude%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bno%20rule%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Ballow%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Ballow%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bno%20rule%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bno%20rule%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bno%20rule%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20no%20rule%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bno%20rule%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EOne%20or%20more%20excludes%20should%20exclude%20the%20donor%2C%20otherwise%20one%20or%20more%20allows%20should%20match%20the%20donor.%20No%20excludes%20and%20no%20allows%20also%20means%20the%20donor%20is%20not%20matched.%20Multiplication%20is%20a%20one-to-one%20map%20onto%20this%20logic%20if%200%20is%20exclude%2C%201%20is%20no%20rule%2C%20and%20%26gt%3B1%20is%20allow.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20criteria1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bcriteria2%26nbsp%3B%20%26nbsp%3B%20criteria3%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B0%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%202%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Edonor3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBy%20multiplying%20the%20numbers%20together%2C%20the%20result%20is%20any%20number%20%26gt%3B%3D2%20means%20the%20donor%20can%20support%20this%20nonprofit.%20Any%20single%20exclude%20will%20result%20in%200.%20Any%20non-rule%20leaves%20the%20result%20alone%20(1).%20Any%20allow%20(2)%20will%20get%20the%20result%20out%20of%20the%200%2F1%20range.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESince%20my%20result%20set%20is%20an%20array%20but%20not%20a%20table%2C%20I'm%20not%20sure%20how%20to%20use%20your%20filter%20suggestion.%20I%20mean%20%22exclude%20any%200%20in%20the%20row.%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEventually%20this%20will%20all%20end%20up%20in%20a%20database%20where%20it%20belongs%2C%20but%20boy%20Excel%20makes%20a%20proof%20of%20concept%20extremely%20fast%20and%20easy.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBy%20the%20way%2C%20your%20comment%20about%20these%20lambdas%20being%20unlike%20anything%20seen%20in%20spreadsheets%20before%2C%20I%20had%20a%20thought%20about%20that.%20The%20array%20functions%20make%20the%20spreadsheet%20data%20much%20more%20like%20a%20database.%20Maybe%20one%20day%20there%20will%20be%20an%20integration%20of%20SQL%20directly%20into%20the%20spreadsheet.%20But%20I%20think%20it's%20interesting%20that%20these%20two%20things%20intersect%3A%20(a)%20lambda%20-%20row%20by%20row%20calculation%20-%20is%20exactly%20what%20you%20attempt%20to%20avoid%20in%20a%20query%2C%20and%20conversely%20(b)%20the%20%22instant%20total%202d%20reduction%22%20that%20I'm%20trying%20to%20get%20around%20here%20is%20actually%20quite%20difficult%20to%20make%20happen%20in%20SQL.%20So%20this%20whole%20powerful%20array%2Flambda%20paradigm%20seems%20to%20be%20at%20the%20intersection%20of%20the%20gap%20between%20(older)%20spreadsheets%20and%20SQL.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2843840%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2843840%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1173763%22%20target%3D%22_blank%22%3E%40boukasa%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20changes%20everything.%26nbsp%3B%20You%20are%20not%20really%20interested%20in%20the%20product%20at%20all%3B%20it%20is%20merely%20an%20AND%20condition%20looking%20for%20an%20instance%20of%20%22exclude%22.%26nbsp%3B%20Negate%20the%20condition%20and%20it%20can%20be%20combined%20by%20addition%2C%20representing%20OR.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20left%20the%20table%20because%20it%20resizes%20to%20accommodate%20fresh%20data%2C%20but%20no%20longer%20use%20the%20structured%20references.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20%20selectedValues%2C%20FILTER(values%2CTabell1%5BOption%5D%3Dselected)%2C%0A%20%20%20%20ones%2C%20%20%20%20%20SEQUENCE(COLUMNS(selectedValues)%2C%2C%2C0)%2C%0A%20%20%20%20inc%2C%20%20%20%20%20%20SIGN(selectedValues%3D%22allow%22)%2C%0A%20%20%20%20exc%2C%20%20%20%20%20%20SIGN(selectedValues%3D%22exclude%22)%2C%0A%20%20%20%20included%2C%20MMULT(inc%2C%20ones)%2C%0A%20%20%20%20excluded%2C%20MMULT(exc%2C%20ones)%2C%0A%20%20%20%20IF(NOT(excluded)%20*%20included%2C%20%22Match%22%2C%20%22---%20%20%20%22)%0A%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eor%20with%20Lambda%20functions%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20%20INCLUDE%CE%BB%2C%20LAMBDA(row%2C%20OR(row%3D%22allow%22))%2C%0A%20%20%20%20EXCLUDE%CE%BB%2C%20LAMBDA(row%2C%20OR(row%3D%22exclude%22))%2C%0A%20%20%20%20excluded%2C%20BYROW(array%23%2C%20EXCLUDE%CE%BB)%2C%0A%20%20%20%20included%2C%20BYROW(array%23%2C%20INCLUDE%CE%BB)%2C%0A%20%20%20%20IF(NOT(excluded)%20*%20included%2C%20%22Match%22%2C%20%22---%20%20%20%22)%0A%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2855156%22%20slang%3D%22en-US%22%3ERe%3A%20Product%20of%20numbers%20in%20a%20row%20in%20a%20dynamic%20array%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2855156%22%20slang%3D%22en-US%22%3EPeter%2C%20yes%20this%20is%20the%20answer%2C%20and%20semantic.%20You%20have%20been%20incredibly%20generous%20with%20your%20time%20and%20knowledge.%20Thanks%20so%20much.%3C%2FLINGO-BODY%3E
Occasional Contributor

How does one do row-by-row evaluations with a 2d dynamic array?

 

For example, I need the product of all the numbers in each row in an array. I can only seem to find ways to get the product of all the numbers in all rows of the array, reduced to a single number.

 

My spilled array:

 

0 2 2

2 1 1

3 3 2

 

Result sought:

 

0

2

18

 

from

 

0*2*2

2*1*1

3*3*2

 

I've struggled mightily and I'm about to resort to some very ugly text manipulation plus a name with evaluate based on the fact that I know my numbers will all be single digits I really do not want to do this!

 

=LET(
 rows, ROW(array)-ROW(INDEX(array,1,1)),
 width, COLUMNS(array),
 astext, TEXTJOIN("*",,array)&"*",
 MID(astext,rows*width*2+1,width*2-1)

)

 

It seems absurd that I can make four rows of text, but not fours rows of results.

 

Thanks for any insights.

 

 

 

13 Replies
best response confirmed by boukasa (Occasional Contributor)
Solution

@boukasa 

This is something I have been complaining about for a couple of years or so now but, as @Jan Karel Pieterse says, the definitive solution is to be found in the Insiders beta Channel.  BYROW will return each row as a distinct range reference and supports any relevant calculation.

 

As an interim workaround, the multiplication of positive numbers may be performed by using logarithms

= EXP(
    MMULT(LN(array#), {1;1;1})
  )

 

@boukasa A Secong solution could be to get each dynamic columns using Index, and multiply them:

 

=INDEX(H4#;SEQUENCE(ROWS(H4#));1)*INDEX(H4#;SEQUENCE(ROWS(H4#));2)*INDEX(H4#;SEQUENCE(ROWS(H4#));3)

 

/Geir

Thanks so much for this workaround! I don't have access to the BYROW function yet, but your solution definitely works for my use case for now. My column count is dynamic so I've made your formula:

=EXP(MMULT(LN(array#),TRANSPOSE(SEQUENCE(1,COLUMNS(array#),1,0))))

Much appreciated!

Geir, thanks so much - my problem includes a dynamic number of columns. I don't fully grasp yet how Excel "views" an array, but I was surprised that you don't seem to be able to use an array for the row/column parameters of INDEX.

@boukasa 

I am not sure what you have in mind for this reply to @Geir Hogstad.   INDEX will accept array and lift the appropriate scalar parameters,  For example

 

= INDEX(array#, {2;5;3}, {4,2,5})

 

would assemble a 3x3 array from a larger array.  It would still have the same problem as the original,

i.e. functions like PRODUCT would still aggregate the entire array, giving a single value.  For row products, you would still need 

 

= BYROW( 
    INDEX(array#, {2;5;3}, {4,2,5}),
    LAMBDA(row, PRODUCT(row))
  )

 

I am just puzzled, not critical.

Peter, I really appreciate you taking the time to look at this. I may have expressed my observation incorrectly or inartfully. Here's an example of what I mean:

In A1, put =SEQUENCE(5,5)
In A7, put =ROW(A1#)-ROW(A1)+1
In B7, put =INDEX(A1#,A7#,0)
In H7, put =INDEX(A1#,A7,0)

I don't understand why B7 doesn't produce full rows (array as parameter to INDEX) but H7 does (non-array as parameter to INDEX). I expected B7 to produce a row, and I also expected to be able to write PRODUCT(INDEX(A1#,A7#,0)) to get my row product - but that not only doesn't work, it reduces to a single result for the whole A1# range.

@boukasa 

What you get from Microsoft is that Excel never has handled 'arrays of arrays' or 'arrays of ranges' and they need to maintain backward compatibility.  Now, however, it has become important because, with dynamic arrays, one keeps hitting the problem.  Your formula

=INDEX(A1#,A7,0)

returns a range object; by that, COLUMN would return sheet column numbers and ISREF would return TRUE.  As soon as you add the # to A7, Excel recognises that you want an array of ranges and blocks the calculation, instead returning an array of single values (it is not a range).

As for

=PRODUCT(INDEX(A1#,A7#,0))

that just suggests that Excel knew perfectly well what you wanted all along, but refused to give it to you!

 

Even with the helper functions MAKEARRAY etc., it can be difficult to return arrays of arrays.

Ha yes Excel reminds me of other relationships I have

I wanted to ask for your thoughts on one issue with the workaround formula you gave me. It doesn't work if there is a 0 in the array because ln(0) is an error. Is there a way to get that to work? I need the 0 result of the product as it has a semantic meaning.

@boukasa 

"... other relationships ..." big grin! 

 

The solution depends upon the semantic meaning.  Taking it as zero, rather than omitted:

= LET(
  selectedValues, FILTER(values,Tabell1[Option]=selected),
  ones, SEQUENCE(COLUMNS(selectedValues),,,0),
  logs, LN(ABS(selectedValues)),
  zeroTest, ISERROR(logs),
  arr, IF(zeroTest, 0, logs),
  result, MMULT(arr, ones),
  isZero, MMULT(SIGN(zeroTest), ones),
  IF(isZero, 0, EXP(result)))

Once you have Lambda functions

= LET(
  PRODUCTλ, LAMBDA(row, PRODUCT(row)),
  BYROW(array#, PRODUCTλ))

would be preferable.  An interesting features of these solutions is that neither looks remotely similar to a traditional spreadsheet formula.

@Peter Bartholomew I can't quite match/figure out how to match your suggestion to my structure. (This is a lot of hoops to get through given that ByRow is coming! But I don't have access to it.)

 

Here's what's really happening. I have a list of donors who will give to any of a list of nonprofits if certain criteria match between the donor's rules and criteria about the nonprofit. Each donor specifies criteria the she excludes or allows. For example, "allow North Texas, exclude Oklahoma, allow women's causes, exclude animal causes, allow this nonprofit, exclude that nonprofit."

 

I can pick a particular nonprofit, look up all its criteria, match it to the allow/exclude rules for the donors, and a complicated formula creates an array that looks like this:

 

                   criteria1     criteria2    criteria3

donor1       exclude     no rule       allow

donor2       allow         no rule       no rule

donor3       no rule      no rule       no rule

 

One or more excludes should exclude the donor, otherwise one or more allows should match the donor. No excludes and no allows also means the donor is not matched. Multiplication is a one-to-one map onto this logic if 0 is exclude, 1 is no rule, and >1 is allow.

 

              criteria1     criteria2    criteria3

donor1       0                1              2

donor2       2                1              1

donor3       1                1              1

 

By multiplying the numbers together, the result is any number >=2 means the donor can support this nonprofit. Any single exclude will result in 0. Any non-rule leaves the result alone (1). Any allow (2) will get the result out of the 0/1 range.

 

Since my result set is an array but not a table, I'm not sure how to use your filter suggestion. I mean "exclude any 0 in the row."

 

Eventually this will all end up in a database where it belongs, but boy Excel makes a proof of concept extremely fast and easy.

 

By the way, your comment about these lambdas being unlike anything seen in spreadsheets before, I had a thought about that. The array functions make the spreadsheet data much more like a database. Maybe one day there will be an integration of SQL directly into the spreadsheet. But I think it's interesting that these two things intersect: (a) lambda - row by row calculation - is exactly what you attempt to avoid in a query, and conversely (b) the "instant total 2d reduction" that I'm trying to get around here is actually quite difficult to make happen in SQL. So this whole powerful array/lambda paradigm seems to be at the intersection of the gap between (older) spreadsheets and SQL. 

@boukasa 

That changes everything.  You are not really interested in the product at all; it is merely an AND condition looking for an instance of "exclude".  Negate the condition and it can be combined by addition, representing OR.  

I have left the table because it resizes to accommodate fresh data, but no longer use the structured references.

= LET(
    selectedValues, FILTER(values,Tabell1[Option]=selected),
    ones,     SEQUENCE(COLUMNS(selectedValues),,,0),
    inc,      SIGN(selectedValues="allow"),
    exc,      SIGN(selectedValues="exclude"),
    included, MMULT(inc, ones),
    excluded, MMULT(exc, ones),
    IF(NOT(excluded) * included, "Match", "---   ")
  )

or with Lambda functions

= LET(
    INCLUDEλ, LAMBDA(row, OR(row="allow")),
    EXCLUDEλ, LAMBDA(row, OR(row="exclude")),
    excluded, BYROW(array#, EXCLUDEλ),
    included, BYROW(array#, INCLUDEλ),
    IF(NOT(excluded) * included, "Match", "---   ")
  )

 

Peter, yes this is the answer, and semantic. You have been incredibly generous with your time and knowledge. Thanks so much.