SOLVED

Help with a big formula using and, xlookup, if and sumifs

%3CLINGO-SUB%20id%3D%22lingo-sub-2689271%22%20slang%3D%22en-US%22%3EHelp%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689271%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20all!%20I'm%20working%20on%20a%20report%20(per%20company%20policy%20can't%20share)%20on%20which%20I%20would%20like%20to%20optimize%20with%20formulas.%20I%20made%20a%20dummy%20example%20as%20close%20as%20I%20could%20so%20I%20could%20explain%20myself%20better%20for%20a%20specific%20case%20I'm%20having%20trouble%20with.%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%22Ccrossed_0-1630002421899.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306074i575FC05BEDE136E4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Ccrossed_0-1630002421899.png%22%20alt%3D%22Ccrossed_0-1630002421899.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELooking%20to%20build%20a%20formula%20to%20do%20the%20following%3A%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESearch%20for%20the%20ID%20number%20on%20the%20master%20list%20ONLY%20IF%3A%3CBR%20%2F%3EOn%20column%20%5BRepeated%3F%5D%20it%20has%20FALSE%2C%20AND%20on%20column%20%5BMODE%5D%20it%20has%20anything%20other%20than%20%22COLLECT%22%20%2F%20Otherwise%20return%20a%200.%3CBR%20%2F%3E-If%20found%2C%20retrieve%20the%20COST%20%3CU%3E%3CSTRONG%3E(if%20the%20number%20repeats%20then%20sum%20all%20costs%20for%20matching%20ID)%3C%2FSTRONG%3E%3C%2FU%3E%3CBR%20%2F%3E-If%20the%20ID%20is%20not%20on%20the%20master%20list%20then%20the%20cost%20must%20be%20calculated%3A%3CBR%20%2F%3ESum%20the%20weight%20on%20all%20matching%20IDs%20and%20multiply%20that%20for%20the%20corresponding%20RATE%20matching%20the%20MODE%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20showing%20what%20I%20have%20built%20so%20far%2C%20and%20the%20cost%20calculation%20works%20but%20cannot%20make%20the%20highlighted%20part%20work%2Fnot%20sure%20how%20to%20add%20it.%3C%2FP%3E%3CP%3E%3DIF(AND(E2%3DFALSE%2CC2%26lt%3B%26gt%3B%22collect%22)%2CXLOOKUP(B2%2CL%3AL%2CM%3AM%2CXLOOKUP(C2%2CI%3AI%2C(J%3AJ)*((SUMIF(B%3AB%2CB2%2CD%3AD)))%2CFALSE%2C0%2C1)%2C0%2C1)%2C0)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20I%20would%20like%20to%20implement%20a%20minimum%20for%20below%20cases%3A%3CBR%20%2F%3EFor%20GROUND%20IDs%20total%20cost%20may%20not%20be%20below%205.28%2C%20if%20the%20calculation%20falls%20below%20that%20it%20must%20return%205.28%3CBR%20%2F%3EFor%20LTL%20IDs%20total%20cost%20may%20not%20fall%20below%2086.11%20so%20it%20must%20return%2086.11%20if%20it%20does.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20open%20to%20all%20suggestions%20as%20well%20as%20questions%20if%20something%20is%20not%20clear%20enough.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2689271%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-2689441%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689441%22%20slang%3D%22en-US%22%3ESince%20it's%20a%20dummy%20file%20to%20begin%20with%2C%20it%20would%20be%20far%20more%20helpful%20to%20post%20that%20dummy%20file%20than%20just%20an%20image%20of%20it.%20That%20way%20we%20could%20work%20with%20the%20file%20rather%20than%20having%20to%20re-create%20it.%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20version%20of%20Excel%20do%20you%20have%3F%20Are%20you%20able%20to%20use%20the%20new%20functions%20like%20UNIQUE%2C%20or%20are%20you%20identifying%20the%20duplicates%20(%22repeated%22)%20manually%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2689487%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689487%22%20slang%3D%22en-US%22%3EAgreed%2C%20I%20have%20attached%20dummy%20file%2C%20also%20i'm%20currently%20using%20Office%20365%20for%20enterprise.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2689866%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689866%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1128056%22%20target%3D%22_blank%22%3E%40Ccrossed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20able%20to%20follow%20your%20explanation%20as%20to%20what%20you're%20trying%20to%20calculate.%20So%20let%20me%20send%20this%20back%20to%20you%20to%20suggest%20another%20function%20that%20might%20be%20helpful%3B%20feel%20free%2C%20though%2C%20to%20come%20back%20with%20clarification.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20entered%20this%20formula%20in%20cell%20O2%3A%26nbsp%3B%3DSORT(UNIQUE(B2%3AC22))%3C%2FP%3E%3CP%3Eto%20get%20this%20array%20of%20unique%20IDs%20and%20associated%20modes%20(UNIQUE%20does%20require%20the%20most%20current%20version%20of%20Excel%2C%20so%20if%20it%20doesn't%20work%2C%20let%20us%20know)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mathetes_0-1630009696398.png%22%20style%3D%22width%3A%20203px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306091i3EF7064C29E23BA6%2Fimage-dimensions%2F203x308%3Fv%3Dv2%22%20width%3D%22203%22%20height%3D%22308%22%20role%3D%22button%22%20title%3D%22mathetes_0-1630009696398.png%22%20alt%3D%22mathetes_0-1630009696398.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EBeyond%20that%2C%20though%2C%20it's%20not%20clear%20to%20me%20what%20the%20relationship%20is%20between%20all%20your%20tables%20and%20what%20you're%20trying%20to%20calculate.%20I%20think%20my%20UNIQUE%20list%20has%20eliminated%20the%20need%20to%20look%20for%20FALSE%20in%20your%20IF%20function...but%2C%20as%20I%20said%2C%20it's%20not%20clear%20to%20me.%20I'd%20like%20to%20make%20it%20a%20more%20elegant%20solution%20if%20possible%2C%20as%20I'm%20sure%20you%20would%20too.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2689879%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689879%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1128056%22%20target%3D%22_blank%22%3E%40Ccrossed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20understood%20the%20logic%20correctly%20that%20could%20be%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DLET(%0A%20%20getSum%2C%20IF(%20ISNA(%20XMATCH(%5B%40ID%5D%2CMasterList%5BMaster%20list%5D)%20)%2C%0A%20%20%20%20%20%20%20%20%20%20XLOOKUP(%5B%40MODE%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Rates%5BMODE%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Rates%5BRATE%5D*SUMIF(%5BID%5D%2C%5B%40ID%5D%2C%5BWEIGHT%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20FALSE%2C0%2C1)%2C%0A%20%20%20%20%20%20%20%20%20%20SUM(%20FILTER(%20MasterList%5BCost%5D%2C%20MasterList%5BMaster%20list%5D%20%3D%20%5B%40ID%5D)%20)%0A%20%20%20%20%20%20%20)%2C%0A%20adjustedSum%2C%20IFS(%20%5B%40MODE%5D%20%3D%20%22Ground%22%2C%20MAX(%205.28%2C%20getSum)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%40MODE%5D%20%3D%20%22LTL%22%2C%20MAX(%2086.11%2C%20getSum)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TRUE%2C%20getSum)%2C%0A%20IF(%20AND(%20%5B%40%5BRepeated%3F%5D%5D%3DFALSE%2C%0A%20%20%20%20%20%20%20%20%20%20%5B%40MODE%5D%26lt%3B%26gt%3B%22collect%22)%2C%0A%20%20%20%20%20adjustedSum%2C%0A%20%20%20%20%200)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2689921%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2689921%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1128056%22%20target%3D%22_blank%22%3E%40Ccrossed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20there%20is%20a%20mistake%20in%20your%20data.%20The%20master%20list%20contains%20a%20duplicate.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2690003%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2690003%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%0A%3CP%3EMy%20understanding%20that%20is%20by%20design.%20If%20ID%3As%20are%20repeated%20in%20Master%20List%20we%20calculate%20sum%20of%20cost%20for%20all%20such%20duplicates.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2692397%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2692397%22%20slang%3D%22en-US%22%3EThanks%20for%20your%20reply%2C%20I%20know%20how%20complex%20this%20worksheet%20is%20so%20I'm%20more%20than%20glad%20to%20clarify%20anything%20possible.%20The%20master%20list%20contains%20a%20record%20of%20IDs%20and%20their%20cost%2C%20these%20can%20be%20repeated%20and%20I'm%20trying%20to%20get%20a%20total%20cost%20for%20said%20ID%2C%20however%20if%20any%20ID%20is%20not%20found%20on%20the%20master%20list%20then%20it%20should%20be%20manually%20calculated%20by%20multiplying%20a%20base%20rate%20(J%3AJ)%20by%20the%20weight%20of%20said%20ID%20(if%20there%20are%20multiple%20matching%20IDs%20it's%20ok%20we%20would%20just%20have%20to%20add%20the%20total%20weight%20before%20getting%20that%20specific%20ID's%20total%20cost)%20However!%3A%20If%20and%20ID%20has%20%22collect%22%20on%20C%3AC%20and%20TRUE%20on%20E%3AE%20then%20it%20shall%20be%20ignored%20and%20given%20a%200%20on%20total%20cost.%20Let%20me%20know%20if%20that%20helps!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2692456%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2692456%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1128056%22%20target%3D%22_blank%22%3E%40Ccrossed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20looks%20like%20suggested%20LET()%20formula%20shall%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2692596%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20a%20big%20formula%20using%20and%2C%20xlookup%2C%20if%20and%20sumifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2692596%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1128056%22%20target%3D%22_blank%22%3E%40Ccrossed%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EApparently%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%26nbsp%3Bunderstands%20the%20spreadsheet%20and%20your%20intent.%20If%20his%20formula%20works%20for%20you%2C%20I'm%20happy%20to%20step%20out%20of%20the%20picture.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20still%20don't%20get%20it.%20Let%20me%2C%20as%20best%20I%20can%2C%20give%20the%20source%20of%20my%20confusion.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20understand%20that%20the%20purpose%20is%20ultimately%20to%20figure%20out%20costs%20to%20be%20attributed%20to%20each%20account.%3C%2FP%3E%3CP%3EBUT%3C%2FP%3E%3CUL%3E%3CLI%3E%3CEM%3Emaster%20list%20contains%20a%20record%20of%20IDs%20and%20their%20cost%20%3A%20%3C%2FEM%3E%3CUL%3E%3CLI%3E%3CSPAN%3Ecost%20of%20%3CSTRONG%3Ewhat%3C%2FSTRONG%3E%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Edoes%20that%20mean%20nothing%20further%20needs%20to%20be%20done%20with%20them%3F%20(pretty%20clearly%20not%2C%20but%20that%20doesn't%20help)%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Eand%20if%20they're%20repeated%2C%20as%20they%20are%2C%20what%20does%20that%20%3CSTRONG%3Emean%3C%2FSTRONG%3E%3F%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAnd%20maybe%20this%20is%20just%20my%20obsessive%20compulsive%20nature%2C%20but%20you%20are%20so%20close%20to%20it%20I%20think%20you%20take%20for%20granted%20the%20context.%20%3CSTRONG%3EIt's%20the%20%22big%20picture%22%20that's%20not%20clear.%3C%2FSTRONG%3E%20I%20have%20no%20idea%20what%20all%20this%20represents%2C%20and%20for%20me%20at%20any%20rate%2C%20knowing%20what%20that%20big%20picture%20is%20helps%20me%20navigate%20the%20details.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

 

Hello all! I'm working on a report (per company policy can't share) on which I would like to optimize with formulas. I made a dummy example as close as I could so I could explain myself better for a specific case I'm having trouble with.

 

Ccrossed_0-1630002421899.png

 

Looking to build a formula to do the following:


Search for the ID number on the master list ONLY IF:
On column [Repeated?] it has FALSE, AND on column [MODE] it has anything other than "COLLECT" / Otherwise return a 0.
-If found, retrieve the COST (if the number repeats then sum all costs for matching ID)
-If the ID is not on the master list then the cost must be calculated:
Sum the weight on all matching IDs and multiply that for the corresponding RATE matching the MODE

 

I'm showing what I have built so far, and the cost calculation works but cannot make the highlighted part work/not sure how to add it.

=IF(AND(E2=FALSE,C2<>"collect"),XLOOKUP(B2,L:L,M:M,XLOOKUP(C2,I:I,(J:J)*((SUMIF(B:B,B2,D:D))),FALSE,0,1),0,1),0)

 

Also, I would like to implement a minimum for below cases:
For GROUND IDs total cost may not be below 5.28, if the calculation falls below that it must return 5.28
For LTL IDs total cost may not fall below 86.11 so it must return 86.11 if it does.

 

I'm open to all suggestions as well as questions if something is not clear enough.

 

Thanks in advance!!

15 Replies

Since it's a dummy file to begin with, it would be far more helpful to post that dummy file than just an image of it. That way we could work with the file rather than having to re-create it.

What version of Excel do you have? Are you able to use the new functions like UNIQUE, or are you identifying the duplicates ("repeated") manually? The most recent version of Excel is needed for that function (and a few others) to operate.

Agreed, I have attached dummy file, also i'm currently using Office 365 for enterprise.

@Ccrossed 

 

I'm not able to follow your explanation as to what you're trying to calculate. So let me send this back to you to suggest another function that might be helpful; feel free, though, to come back with clarification.

 

I entered this formula in cell O2: =SORT(UNIQUE(B2:C22))

to get this array of unique IDs and associated modes (UNIQUE does require the most current version of Excel, so if it doesn't work, let us know)

mathetes_0-1630009696398.png

Beyond that, though, it's not clear to me what the relationship is between all your tables and what you're trying to calculate. I think my UNIQUE list has eliminated the need to look for FALSE in your IF function...but, as I said, it's not clear to me. I'd like to make it a more elegant solution if possible, as I'm sure you would too.

 

best response confirmed by Ccrossed (Occasional Contributor)
Solution

@Ccrossed 

If I understood the logic correctly that could be

=LET(
  getSum, IF( ISNA( XMATCH([@ID],MasterList[Master list]) ),
          XLOOKUP([@MODE],
                   Rates[MODE],
                   Rates[RATE]*SUMIF([ID],[@ID],[WEIGHT]),
                   FALSE,0,1),
          SUM( FILTER( MasterList[Cost], MasterList[Master list] = [@ID]) )
       ),
 adjustedSum, IFS( [@MODE] = "Ground", MAX( 5.28, getSum),
                   [@MODE] = "LTL", MAX( 86.11, getSum),
                   TRUE, getSum),
 IF( AND( [@[Repeated?]]=FALSE,
          [@MODE]<>"collect"),
     adjustedSum,
     0)
)

 

@Ccrossed 

I think there is a mistake in your data. The master list contains a duplicate.

 

@Detlef Lewin 

My understanding that is by design. If ID:s are repeated in Master List we calculate sum of cost for all such duplicates.

Thanks for your reply, I know how complex this worksheet is so I'm more than glad to clarify anything possible. The master list contains a record of IDs and their cost, these can be repeated and I'm trying to get a total cost for said ID, however if any ID is not found on the master list then it should be manually calculated by multiplying a base rate (J:J) by the weight of said ID (if there are multiple matching IDs it's ok we would just have to add the total weight before getting that specific ID's total cost) However!: If and ID has "collect" on C:C and TRUE on E:E then it shall be ignored and given a 0 on total cost. Let me know if that helps!

@Ccrossed 

It looks like suggested LET() formula shall work.

@Ccrossed 

 

Apparently @Sergei Baklan understands the spreadsheet and your intent. If his formula works for you, I'm happy to step out of the picture.

 

I still don't get it. Let me, as best I can, give the source of my confusion. 

I do understand that the purpose is ultimately to figure out costs to be attributed to each account.

BUT

  • master list contains a record of IDs and their cost :
    • cost of what
    • does that mean nothing further needs to be done with them? (pretty clearly not, but that doesn't help)
    • and if they're repeated, as they are, what does that mean?

 

And maybe this is just my obsessive compulsive nature, but you are so close to it I think you take for granted the context. It's the "big picture" that's not clear. I have no idea what all this represents, and for me at any rate, knowing what that big picture is helps me navigate the details.

 

@Ccrossed 

***


@Ccrossed wrote:
The master list contains a record of IDs and their cost, these can be repeated and I'm trying to get a total cost for said ID


A master list should contain unique IDs and no duplicates.

Why don't you change the two entries from 100+50 to one entry with 150?

 

 

@Detlef Lewin , I don't know what is the logic behind, but it's possible to do the calculation with duplicates. Not as easy as with unique ID:s, but it works.

Thank you Sergei, it seems to be doing its job. One thing tho, would it be possible to adapt this formula from a table to a range? Original document is continuously growing with now more than 2k rows and each of the tables here are on separate tabs. Thanks!

@Ccrossed 

You may but I see no one reason to do that. Structured table automatically add formulas to new rows. It doesn't matter in which sheet you place the table, only table name is used.

Thus you don't need enter formulas to new rows, just add your data and table does the rest.

 

However, you may stay on the table, convert it to the range from menu and formula will be adjusted automatically. Reference on entire column in formulae is always not a good idea, obvious side effect is performance. To improve it you may use dynamic ranges like

=LET(
  masterListID,    $L$2:INDEX($L:$L,COUNTA($L:$L)),
  masterListCost, $M$2:INDEX($M:$M,COUNTA($M:$M)),
  mode,           $I$2:INDEX($I:$I,COUNTA($I:$I)),
  rate,           $J$2:INDEX($J:$J,COUNTA($J:$J)),
  ID,             $B$2:INDEX($B:$B,COUNTA($B:$B)),
  weight,         $D$2:INDEX($D:$D,COUNTA($D:$D)),
  getSum, IF( ISNA( XMATCH($B2,masterListID ) ),
          XLOOKUP( $C2,
                    mode,
                    rate*SUMIF(ID,$B2,weight),
                    FALSE,0,1),
          SUM( FILTER( masterListCost, masterListID = $B2) )
       ),
 adjustedSum, IFS( $C2 = "Ground", MAX( 5.28, getSum),
                   $C2 = "LTL", MAX( 86.11, getSum),
                   TRUE, getSum),
 IF( AND( $E2=FALSE,
          $C2<>"collect"),
      adjustedSum,
      0)
)

but in any case you shall be sure nothing is added below main data in columns you use. Please check in attached.

 

In general structured tables were made to improve calculations in cases like yours. But what to use is always your decision.

@Sergei Baklan 

Awesome! yes I also believe a table would be a more efficient way of dealing with the data, so I'm definitely gonna propose that change to our reports. One last thing I would like help with would be to update the formula to look into different sheets for the complementary tables, this so I can translate the formula to our main workbook as smoothly as possible. My knowledge on Excel is still limited so I'm having some trouble understanding some components on your formula.

 

New dummy attached.

@Ccrossed 

Formula will be

=LET(
  masterListID,   Sheet3!$A$2:INDEX(Sheet3!$A:$A,COUNTA(Sheet3!$A:$A)),
  masterListCost, Sheet3!$B$2:INDEX(Sheet3!$B:$B,COUNTA(Sheet3!$B:$B)),
  mode,           Sheet2!$A$2:INDEX(Sheet2!$A:$A,COUNTA(Sheet2!$A:$A)),
  rate,           Sheet2!$B$2:INDEX(Sheet2!$B:$B,COUNTA(Sheet2!$B:$B)),
  ID,             $A$2:INDEX($A:$A,COUNTA($A:$A)),
  weight,         $C$2:INDEX($C:$C,COUNTA($C:$C)),
  getSum, IF( ISNA( XMATCH($A2,masterListID ) ),
          XLOOKUP( $B2,
                   mode,
                   rate*SUMIF(ID,$A2,weight),
                   FALSE,0,1),
          SUM( FILTER( masterListCost, masterListID = $A2) )
       ),
 adjustedSum, IFS( $B2 = "Ground", MAX( 5.28, getSum),
                   $B2 = "LTL", MAX( 86.11, getSum),
                   TRUE, getSum),
 IF( AND( $D2=FALSE,
          $B2<>"collect"),
      adjustedSum,
      0)
)

Please check in attached.