Profit Formula Challenge

%3CLINGO-SUB%20id%3D%22lingo-sub-1791626%22%20slang%3D%22en-US%22%3EProfit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1791626%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20believe%20you%20can%20comfortably%20manipulate%20arrays%2C%20then%20these%20six%20formula%20challenges%20will%20test%20your%20mettle!%20I%20superbly%20love%20the%20sixth.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Profit%20Formula%20Challenge.PNG%22%20style%3D%22width%3A%20895px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227362i8894395D04A93637%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Profit%20Formula%20Challenge.PNG%22%20alt%3D%22Profit%20Formula%20Challenge.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1791626%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1791880%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1791880%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20thing%20that%20might%20have%20defeated%20me%20is%20the%20spirit%20of%20'No%20CSE'.%26nbsp%3B%20About%205%20years%20ago%20I%20had%20schooled%20myself%20to%20use%20CSE%20for%20almost%20all%20formulas%20in%20order%20to%20avoid%20filled%20formulas%20and%20relative%20referencing.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20developed%20the%20technique%20of%20using%20named%20formulas%20to%20avoid%20the%20dreaded%20implicit%20intersection%20and%20ensure%20calculations%20were%20performed%20correctly%20as%20arrays.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20it%20doesn't%20matter%20since%20I%20am%20using%20Excel%20365.%26nbsp%3B%20My%20formulas%20would%20not%20meet%20the%20criteria%20but%20...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20SUM(%20SignCashFlow%20*%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%20)%0A%0A%3D%20LET(%0A%20%20crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20OperatingProfit%2C%20MMULT(%20TRANSPOSE(SignCashFlow)%2C%20crosstab%20)%2C%0A%20%20COUNT(%20IF(OperatingProfit%20%26gt%3B%200%2C%201)%20)%20)%0A%0A%3D%20LET(%0A%20%20crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20OperatingProfit%2C%20MMULT(%20TRANSPOSE(SignCashFlow)%2C%20crosstab%20)%2C%0A%20%20MinProfit%2C%20MIN(OperatingProfit)%2C%0A%20%20MaxProfit%2C%20MAX(OperatingProfit)%2C%0A%20%20XLOOKUP(%20MaxProfit%2C%20OperatingProfit%2C%20HdrBranches%20)%20)%0A%0A%3D%20LET(%0A%20%20crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20OperatingProfit%2C%20MMULT(%20TRANSPOSE(SignCashFlow)%2C%20crosstab%20)%2C%0A%20%20MinProfit%2C%20MIN(OperatingProfit)%2C%0A%20%20MaxProfit%2C%20MAX(OperatingProfit)%2C%0A%20%20MaxProfit%20-%20MinProfit%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1791953%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1791953%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%3C%2FP%3E%3CP%3EThe%20thing%20that%20might%20have%20defeated%20me%20is%20the%20spirit%20of%20'No%20CSE'.%26nbsp%3B%20About%205%20years%20ago%20I%20had%20schooled%20myself%20to%20use%20CSE%20for%20almost%20all%20formulas%20in%20order%20to%20avoid%20filled%20formulas%20and%20relative%20referencing.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EI%20also%20developed%20the%20technique%20of%20using%20named%20formulas%20to%20avoid%20the%20dreaded%20implicit%20intersection%20and%20ensure%20calculations%20were%20performed%20correctly%20as%20arrays.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20it%20doesn't%20matter%20since%20I%20am%20using%20Excel%20365.%26nbsp%3B%20My%20formulas%20would%20not%20meet%20the%20criteria%20but%20...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20%20OperatingProfit%2C%20MMULT(TRANSPOSE(SignCashFlow)%2C%20crosstab)%2C%0A%20%20%20ProfitableBranches%2C%20COUNT(%20IF(OperatingProfit%26gt%3B0%2C%201))%2C%0A%20%20%20LossmakingBranches%2C%20COUNT(%20IF(OperatingProfit%26lt%3B0%2C%201))%2C%0A%20%20%20MinProfit%2C%20MIN(OperatingProfit)%2C%0A%20%20%20MaxProfit%2C%20MAX(OperatingProfit)%2C%0A%20%20%20BestPerforming%2C%20XLOOKUP(MaxProfit%2C%20OperatingProfit%2C%20HdrBranches)%2C%0A%20%20%20WorstPerforming%2CXLOOKUP(MinProfit%2C%20OperatingProfit%2C%20HdrBranches)%2C%0A%20%20%20CHOOSE(%7B1%3B2%3B3%3B4%3B5%3B6%7D%2C%0A%20%20%20%20%20%20SUM(OperatingProfit)%2C%0A%20%20%20%20%20%20ProfitableBranches%2C%0A%20%20%20%20%20%20LossmakingBranches%2C%0A%20%20%20%20%20%20BestPerforming%2C%0A%20%20%20%20%20%20WorstPerforming%2C%0A%20%20%20%20%20%20MaxProfit%20-%20MinProfit)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20formula%20avoids%20the%20need%20to%20repeat%20the%20SUMIFS%20step%20by%20retuning%20all%20six%20results%20as%20a%20single%20array.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792047%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792047%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%3B%2C%20in%20opposite%20I%20schooled%20myself%20to%20avoid%20CSE%20where%20possible.%20But%20by%20another%20formulas.%20Simplest%20cases%20SUMPRODUCT()%20instead%20of%20SUM()%2C%20MATCH%2FINDEX%20instead%20of%20MATCH%2C%20etc.%20Yes%2C%20I%20know%20about%20the%20names.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792135%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792135%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20far%20more%20normal%20strategy%20I%20agree.%26nbsp%3B%20On%20the%20other%20hand%20SUMPRODUCT%20and%2C%20I%20think%2C%20AGGREGATE%20are%20array%20formulas%2C%20just%20no%20CSE.%26nbsp%3B%20It%20is%20mainly%20the%20user%20hostility%20to%20the%20presentation%20of%20CSE%20formulas%20that%20makes%20them%20viewed%20as%20methods%20of%20last%20resort%20-%20too%20clever%20by%20half!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELogically%20Excel%20should%20prevent%20a%20blank%20line%20from%20being%20inserted%20between%20a%20formula%20and%20any%20of%20its%20relative%20reference%20because%20the%20meaning%20is%20ambiguous%2C%20but%20that%20doesn't%20happen%20because%20in%20standard%20Excel%20practice%20the%20risk%20of%20error%20is%20less%20important%20that%20the%20fluency%20of%20the%20action-led%20user%20interface.%26nbsp%3B%20Instead%2C%20it%20is%20the%20array%20formula%20that%20blocks%20the%20insertion%20of%20rows%2C%20despite%20there%20being%20no%20such%20ambiguity.%26nbsp%3B%20I%20seem%20to%20remember%20a%20message%20such%20as%20'you%20cannot%20change%20part%20of%20an%20array%20formula'.%26nbsp%3B%20Since%20I%20cannot%20insert%20a%20blank%20cell%20into%20the%20middle%20of%20an%20array%20wouldn't%20it%20be%20more%20logical%20to%20assume%20I%20do%20not%20wish%20to%20and%20simple%20repaint%20the%20array%20unaltered%20just%20as%20a%20DA%20does%20now%20(an%20extra%20%23N%2FA!%20at%20the%20end%20if%20must%20be).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20was%20an%20uphill%20grind%20to%20switch%20to%20array%20formulas%20but%20now%2C%20thankfully%2C%20the%20position%20is%20now%20reversed.%26nbsp%3B%20If%20I%20were%20forced%20to%20revert%20to%20'enter%20the%20formula%20in%20cell%20%24PQ17%20and%20fill%20down%201027%20cells'%2C%20I%20think%20I%20would%20just%20delete%20Excel%20and%20use%20a%20pocket%20calculator%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792160%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792160%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%3B%3C%2FP%3E%0A%3CP%3EYes%2C%20arrays%20were%20all%20the%20time%2C%20just%20before%20in%20back-end%20and%20you%20shall%20to%20know%20what%20is%20behind%20and%20which%20formulas%20to%20use%2C%20now%20they%20are%20on%20front-end.%20Hope%20that's%20only%20the%20first%2C%20but%20significant%20one%2C%20step%20and%20we%20will%20be%20able%20to%20manipulate%20not%20only%20with%20entire%20array%20as%20an%20object%2C%20but%20with%20each%20element%20of%20it.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20the%20way%2C%20I%20see%20nothing%20dramatic%20in%20Fill%20Down%2C%20doesn't%20matter%20on%20couple%20of%20cells%20or%20on%20couple%20thousand%20of%20cells.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792267%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792267%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20could%20amplify%20why%20I%20feel%20single%20cell%20relative%20referencing%20is%20a%20slap-dash%20approach%2C%20though%20in%20keeping%20with%20the%20idea%20of%20end-user%20computing.%26nbsp%3B%20That%20would%20take%20the%20discussion%20too%20far%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%26nbsp%3B's%26nbsp%3Bchallenge%20though%2C%20and%20I%20would%20like%20to%20see%20what%20others%20come%20up%20with.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792370%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792370%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%3Band%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%2C%20I%20edited%20my%20post%20to%20include%20two%20additional%20challenges%2C%20thereby%20bringing%20the%20total%20to%20eight.%20Please%20see%20the%20revised%20version%20of%20the%20file%20attached%20thereto.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792552%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792552%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20confess%2C%20I%20have%20never%20seen%20or%20attempted%20a%20formula%20this%20large%20in%20Excel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20%20OperatingProfit%2C%20MMULT(%20TRANSPOSE(SignCashFlow)%2C%20crosstab%20)%2C%0A%20%20%20ProfitableBranches%2C%20COUNT(%20IF(OperatingProfit%20%26gt%3B%200%2C%201)%20)%2C%0A%20%20%20LossmakingBranches%2C%20COUNT(%20IF(OperatingProfit%20%26lt%3B0%2C%201)%20)%2C%0A%20%20%20MaxProfit%2C%20MAX(OperatingProfit)%2C%0A%20%20%20BestPerforming%2C%20XLOOKUP(%20MaxProfit%2C%20OperatingProfit%2C%20HdrBranches%20)%2C%0A%20%20%20MaxLoss%2C%20MIN(OperatingProfit)%2C%0A%20%20%20WorstPerforming%2C%20XLOOKUP(%20MaxLoss%2C%20OperatingProfit%2C%20HdrBranches%20)%2C%0A%20%20%20MinGain%2C%20MIN(IF(OperatingProfit%26gt%3B0%2C%20OperatingProfit)%20)%2C%0A%20%20%20MinGainBranch%2C%20XLOOKUP(%20MinGain%2C%20OperatingProfit%2C%20HdrBranches%20)%2C%0A%20%20%20MinLoss%2C%20MAX(IF(OperatingProfit%26lt%3B0%2C%20OperatingProfit)%20)%2C%0A%20%20%20MinLossBranch%2C%20XLOOKUP(%20MinLoss%2C%20OperatingProfit%2C%20HdrBranches%20)%2C%0A%20%20%20CHOOSE(%7B1%3B2%3B3%3B4%3B5%3B6%3B7%3B8%7D%2C%0A%20%20%20%20%20%20SUM(OperatingProfit)%2C%0A%20%20%20%20%20%20ProfitableBranches%2C%0A%20%20%20%20%20%20LossmakingBranches%2C%0A%20%20%20%20%20%20BestPerforming%2C%0A%20%20%20%20%20%20WorstPerforming%2C%0A%20%20%20%20%20%20MinGainBranch%2C%0A%20%20%20%20%20%20MinLossBranch%2C%0A%20%20%20%20%20%20MaxProfit-MaxLoss%20)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20it%20be%20better%20to%20break%20the%20calculation%20into%20parts%20even%20though%20it%20would%20mean%20recalculating%20the%20SUMIFS%20calculation%20within%20formula%3F%20I%20could%2C%20for%20example%2C%20have%20produced%20an%20array%20of%20MAX%2FMINs%20and%20then%20performed%20an%20XLOOKUP%20on%20the%20array.%3C%2FP%3E%3CP%3EAlternatively%2C%20should%20I%20have%20nested%20the%20MAX%2FMINs%20within%20the%20XLOOKUP%20to%20reduce%20the%20count%20of%20LET%20parameters%3F%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%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-1792750%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792750%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%2C%20me%20too!%20But%20would%20you%20believe%20me%20if%20I%20tell%20you%20each%20of%20my%20formulas%20did%20not%20exceed%20200%20characters%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792838%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792838%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20faith%20in%20you%2C%20so%20yes%20I%20am%20prepared%20to%20believe%20the%20200%20characters.%26nbsp%3B%20I%20would%20also%20agree%20that%20conciseness%20is%20good%2C%20but%20it%20is%20not%20the%20only%20metric%20of%20relevance.%26nbsp%3B%20Comparing%20solutions%20will%20always%20have%20an%20element%20of%20subjectivity%20because%20the%20secondary%20objectives%20can%20be%20so%20different%20(getting%20the%20answer%20right%20is%20not%20so%20controversial).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EClearly%20my%20selection%20of%20names%20such%20as%20'OperatingProfit'%20and%20'LossmakingBranches'%20does%20not%20serve%20the%20cause%20of%20conciseness%20too%20well!%26nbsp%3B%20On%20the%20other%20hand%2C%20I%20did%20consider%20the%20number%20of%20floating%20point%20operations%20implicit%20in%20the%20formulas%20and%20it%20was%20that%20which%20led%20me%20to%20the%20unusual%20strategy%20of%20combining%20the%208%20distinct%20calculations%20into%20a%20single%20formula.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20formula%20appears%20to%20be%20950%20characters%20(including%20the%20140%20spaces%20used%20to%20improve%20layout).%26nbsp%3B%20That%20is%20not%20too%20bad%20when%20one%20considers%20that%20it%20delivers%20all%208%20calculations.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20be%20interested%20to%20see%20your%20solution%20when%20you%20are%20ready%20to%20communicate%20it.%26nbsp%3B%20Did%20the%20'no%20CSE'%20rule%20impact%20you%20significantly%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1792916%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1792916%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%2C%20I%20agree%20with%20you%20that%20the%20choice%20of%20formulas%20is%20somehow%20a%20matter%20of%20personal%20preference%2C%20hence%20usually%20subjective.%20Like%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%2C%20I%20schooled%20myself%20to%20exploit%20the%20powers%20of%20functions%20that%20can%20natively%20process%20array%20operations.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1794877%22%20slang%3D%22en-US%22%3ERe%3A%20Profit%20Formula%20Challenge%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1794877%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F280482%22%20target%3D%22_blank%22%3E%40Twifoo%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20my%20response%20has%20not%20put%20others%20off%20contributing%20traditional%20spreadsheet%20solutions!%3C%2FP%3E%3CP%3EThe%20solutions%20I%20am%20exploring%20are%20not%20available%20within%20most%20Excel%20versions%20and%20would%20not%20suit%20many%20users.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20new%20modification%20to%20my%20solution%2C%20I%20have%20made%20it%20more%20targeted%20and%20eliminated%20a%20number%3C%2FP%3E%3CP%3Eof%20intermediate%20variables.%26nbsp%3B%20The%20image%20below%20shows%20the%20spilt%20range%20output%20from%20a%20single%20formula%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20465px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227632iB1B5004FD0660709%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20Crosstab%2C%20SUMIFS(Amounts%2C%20Types%2C%20listTypes%2C%20Branches%2C%20HdrBranches)%2C%0A%20%20OperatingProfit%2C%20MMULT(%20TRANSPOSE(SignCashFlow)%2C%20Crosstab%20)%2C%0A%20%20Profits%2C%20IF(OperatingProfit%20%26gt%3B%200%2C%20OperatingProfit)%2C%0A%20%20Losses%2C%20IF(OperatingProfit%26lt%3B%3D%200%2C%20-OperatingProfit)%2C%0A%0A%20%20%20KeyMetrics%2CHSTACK(%22%22%2C%20%0A%20%20%20%20%20SUM(OperatingProfit)%2C%20COUNT(Profits)%2C%20COUNT(Losses)%2C%20MAX(Profits)%2BMAX(Losses))%2C%0A%20%20%20ExtremeValues%2C%20HSTACK(%22%22%2C%20MAX(Profits)%2C%20MIN(Profits)%2C%20-MIN(Losses)%2C%20-MAX(Losses))%2C%0A%20%20%20AssociatedBranches%2C%20XLOOKUP(%20ExtremeValues%2C%20OperatingProfit%2C%20HdrBranches)%2C%0A%20%20%20VSTACK(%22%22%2C%20Headings1%2C%20KeyMetrics%2C%20Headings2%2C%20AssociatedBranches%2C%20ExtremeValues)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20have%20chosen%20to%20show%20formulas%20using%20Charles%20Williams's%20HSTACK%20and%20VSTACK%20functions%20because%20the%20intent%20is%20clearer%2C%20but%20CHOOSE%20with%20the%20correctly%20oriented%20index%20arrays%20will%20achieve%20the%20same%20result.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Trusted Contributor

If you believe you can comfortably manipulate arrays, then these eight formula challenges will test your mettle! I superbly love the sixth. 

Profit Formula Challenge.png

17 Replies
Highlighted

@Twifoo@Twifoo

The thing that might have defeated me is the spirit of 'No CSE'.  About 5 years ago I had schooled myself to use CSE for almost all formulas in order to avoid filled formulas and relative referencing.  

I also developed the technique of using named formulas to avoid the dreaded implicit intersection and ensure calculations were performed correctly as arrays.

 

Now it doesn't matter since I am using Excel 365.  My formulas would not meet the criteria but ...

 

 

 

= LET(
  crosstab, SUMIFS(Amounts,Types,listTypes,Branches,HdrBranches),
  OperatingProfit, MMULT(TRANSPOSE(SignCashFlow), crosstab),
  ProfitableBranches, COUNT( IF(OperatingProfit>0, 1)),
  LossmakingBranches, COUNT(IF(OperatingProfit<0, 1)),
  MinProfit, MIN(OperatingProfit),
  MaxProfit, MAX(OperatingProfit),
  BestPerforming, XLOOKUP(MaxProfit,OperatingProfit,HdrBranches),
  WorstPerforming,XLOOKUP(MinProfit,OperatingProfit,HdrBranches),
  CHOOSE({1;2;3;4;5;6},
    SUM(OperatingProfit),
    ProfitableBranches,
    LossmakingBranches,
    BestPerforming,
    WorstPerforming,
    MaxProfit - MinProfit) )

 

 

 

The formula avoids the need to repeat the SUMIFS step by retuning all six results as a single array.

Highlighted

@Peter Bartholomew , in opposite I schooled myself to avoid CSE where possible. But by another formulas. Simplest cases SUMPRODUCT() instead of SUM(), MATCH/INDEX instead of MATCH, etc. Yes, I know about the names.

Highlighted

@Sergei Baklan 

A far more normal strategy I agree.  On the other hand SUMPRODUCT and, I think, AGGREGATE are array formulas, just no CSE.  It is mainly the user hostility to the presentation of CSE formulas that makes them viewed as methods of last resort - too clever by half!

 

Logically Excel should prevent a blank line from being inserted between a formula and any of its relative reference because the meaning is ambiguous, but that doesn't happen because in standard Excel practice the risk of error is less important that the fluency of the action-led user interface.  Instead, it is the array formula that blocks the insertion of rows, despite there being no such ambiguity.  I seem to remember a message such as 'you cannot change part of an array formula'.  Since I cannot insert a blank cell into the middle of an array wouldn't it be more logical to assume I do not wish to and simple repaint the array unaltered just as a DA does now (an extra #N/A! at the end if must be).

 

It was an uphill grind to switch to array formulas but now, thankfully, the position is now reversed.  If I were forced to revert to 'enter the formula in cell $PQ17 and fill down 1027 cells', I think I would just delete Excel and use a pocket calculator

Highlighted

@Peter Bartholomew 

Yes, arrays were all the time, just before in back-end and you shall to know what is behind and which formulas to use, now they are on front-end. Hope that's only the first, but significant one, step and we will be able to manipulate not only with entire array as an object, but with each element of it. 

 

By the way, I see nothing dramatic in Fill Down, doesn't matter on couple of cells or on couple thousand of cells.

Highlighted

@Sergei Baklan 

I could amplify why I feel single cell relative referencing is a slap-dash approach, though in keeping with the idea of end-user computing.  That would take the discussion too far from @Twifoo 's challenge though, and I would like to see what others come up with.

Highlighted

@Peter Bartholomew and @Sergei Baklan, I edited my post to include two additional challenges, thereby bringing the total to eight. Please see the revised version of the file attached thereto. 

Highlighted

@Twifoo 

I confess, I have never seen or attempted a formula this large in Excel.

 

= LET(
   crosstab, SUMIFS(Amounts, Types, listTypes, Branches, HdrBranches),
   OperatingProfit, MMULT( TRANSPOSE(SignCashFlow), crosstab ),
   ProfitableBranches, COUNT( IF(OperatingProfit > 0, 1) ),
   LossmakingBranches, COUNT( IF(OperatingProfit <0, 1) ),
   MaxProfit, MAX(OperatingProfit),
   BestPerforming, XLOOKUP( MaxProfit, OperatingProfit, HdrBranches ),
   MaxLoss, MIN(OperatingProfit),
   WorstPerforming, XLOOKUP( MaxLoss, OperatingProfit, HdrBranches ),
   MinGain, MIN(IF(OperatingProfit>0, OperatingProfit) ),
   MinGainBranch, XLOOKUP( MinGain, OperatingProfit, HdrBranches ),
   MinLoss, MAX(IF(OperatingProfit<0, OperatingProfit) ),
   MinLossBranch, XLOOKUP( MinLoss, OperatingProfit, HdrBranches ),
   CHOOSE({1;2;3;4;5;6;7;8},
      SUM(OperatingProfit),
      ProfitableBranches,
      LossmakingBranches,
      BestPerforming,
      WorstPerforming,
      MinGainBranch,
      MinLossBranch,
      MaxProfit-MaxLoss ) )

 

Would it be better to break the calculation into parts even though it would mean recalculating the SUMIFS calculation within formula? I could, for example, have produced an array of MAX/MINs and then performed an XLOOKUP on the array.

Alternatively, should I have nested the MAX/MINs within the XLOOKUP to reduce the count of LET parameters?

 

 

 

Highlighted

@Peter Bartholomew, me too! But would you believe me if I tell you each of my formulas did not exceed 200 characters?

Highlighted

@Twifoo 

I have faith in you, so yes I am prepared to believe the 200 characters.  I would also agree that conciseness is good, but it is not the only metric of relevance.  Comparing solutions will always have an element of subjectivity because the secondary objectives can be so different (getting the answer right is not so controversial).

 

Clearly my selection of names such as 'OperatingProfit' and 'LossmakingBranches' does not serve the cause of conciseness too well!  On the other hand, I did consider the number of floating point operations implicit in the formulas and it was that which led me to the unusual strategy of combining the 8 distinct calculations into a single formula.

 

My formula appears to be 950 characters (including the 140 spaces used to improve layout).  That is not too bad when one considers that it delivers all 8 calculations.

 

I will be interested to see your solution when you are ready to communicate it.  Did the 'no CSE' rule impact you significantly?

Highlighted

@Peter Bartholomew, I agree with you that the choice of formulas is somehow a matter of personal preference, hence usually subjective. Like @Sergei Baklan, I schooled myself to exploit the powers of functions that can natively process array operations.

Highlighted

@Twifoo 

I hope my response has not put others off contributing traditional spreadsheet solutions!

The solutions I am exploring are not available within most Excel versions and would not suit many users.

 

In the new modification to my solution, I have made it more targeted and eliminated a number

of intermediate variables.  The image below shows the spilt range output from a single formula

 

image.png

 

= LET(
  Crosstab, SUMIFS(Amounts, Types, listTypes, Branches, HdrBranches),
  OperatingProfit, MMULT( TRANSPOSE(SignCashFlow), Crosstab ),
  Profits, IF(OperatingProfit > 0, OperatingProfit),
  Losses, IF(OperatingProfit<= 0, -OperatingProfit),

   KeyMetrics,HSTACK("", 
     SUM(OperatingProfit), COUNT(Profits), COUNT(Losses), MAX(Profits)+MAX(Losses)),
   ExtremeValues, HSTACK("", MAX(Profits), MIN(Profits), -MIN(Losses), -MAX(Losses)),
   AssociatedBranches, XLOOKUP( ExtremeValues, OperatingProfit, HdrBranches),
   VSTACK("", Headings1, KeyMetrics, Headings2, AssociatedBranches, ExtremeValues) )

I have chosen to show formulas using Charles Williams's HSTACK and VSTACK functions because the intent is clearer, but CHOOSE with the correctly oriented index arrays will achieve the same result.

 

 

Highlighted

@Peter Bartholomew 

Although you indirectly admitted that your solution is inherently inapplicable to most Excel users, it nonetheless behooves me to commend you for your tenacious pursuit thereof! Before I ultimately divulge my solutions, I deem it prudent to meanwhile anticipate possible solutions from @Sergei Baklan, and other Excel Experts from this Community. 

Highlighted

@Twifoo , sorry, perhaps some later, bit overloaded with current project and answer here only to have some rest and if that takes not more than 5 minutes. Your task looks quite interesting, but I'm very far from accounting world and for me to understand what "Combined bottom line of All Branches" means will take significant time.

 

@Peter Bartholomew  solutions looks interesting, but as I avoided CSE I try to avoid any macros and third-party add-ins. Charles suggests great additions, however I'd prefer to wait till the same will be out of the box.

 

Highlighted

@Sergei Baklan 

Don't worry, I empathize with you. Bottom Line simple means the final amount, which refers to the values in the row for Operating Profit. Thus, Combined Bottom Line of All Branches refers to the value for Total Operating Profit, which is 45,800.00. I trust that I have somehow clarified your doubts as to the terms used in this formula challenge. By the way, Accounting is the language of business! It is only through Accounting that business information can be communicated to the users thereof. 

Highlighted

@Sergei Baklan 

Like you, I avoid add-ins especially when sharing ideas with others.   @Charles Williams  work I have enjoyed, though, and I hope some of his ideas eventually get adopted by Microsoft.  I have found the array manipulation offered in the form of slicing and stacking, ACCUMULATE for accountancy corkscrew problems and some of the Regular Expression formulas to be particularly effective.  I did include a working version of the present formula based on CHOOSE, because people tend to be unimpressed when they open a workbook that refuses to calculate.

= LET(
   Crosstab, SUMIFS(Amounts, Types, listTypes, Branches, HdrBranches),
   OperatingProfit, MMULT( TRANSPOSE(SignCashFlow), Crosstab ),
   Profits, IF(OperatingProfit > 0, OperatingProfit),
   Losses, IF(OperatingProfit<= 0, -OperatingProfit),

   KeyMetrics, CHOOSE({1,2,3,4}, SUM(OperatingProfit), COUNT(Profits), COUNT(Losses), MAX(Profits)+MAX(Losses)),
   ExtremeValues, CHOOSE({1,2,3,4}, MAX(Profits), MIN(Profits), - MIN(Losses), -MAX(Losses)),
   AssociatedBranches, XLOOKUP( ExtremeValues, OperatingProfit, HdrBranches),
   CHOOSE({1;2;3;4;5}, Headings1, KeyMetrics, Headings2, AssociatedBranches, ExtremeValues) )

 

Highlighted

@Peter Bartholomew 

So, we are almost in sync.

Highlighted

@Twifoo , thank you for the clarification. Yes, sure , accounting is the language of business, but English terms are not always understandable if your business uses another language.