Show Total Only Once for Order# with Multiple Lines

jarett

Board Regular
Joined
Apr 12, 2021
Messages
165
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this spreadsheet that contains order lines, some orders only have one line, easy enough to display to "net invoice" total. The orders with multiple lines is where I am stuck. If the order has multiple lines, the "additional charges/deductions" are always on the first line of the order. So if an order has multiple lines I need to add the (total of column L to column M+N)-O=P, and I only want to display P on the first line of the order. Column L is a detail field and M,N,O are all header fields in the DB I am pulling from.

INVOICE 03012024.xlsx
BCDEFGHIJKLMNOP
1SalesOrderNoInvoiceDateUDF_EMPLOYEE_NAMEUDF_EXTCUSTPOUDF_EXTRAORDERINFORMATIONItemCodeItemCodeDescShipToCityShipToStateShipToZipCodeExtensionAmtFreightAmtSalesTaxAmtDepositAmtNet Invoice
284323103/1/2024 0:00AGUSTIN RODRIGUEZIKIHWYN7JGARYVILLE8051-33BKHigh Sierra Elite Fly-By 17 inWalkerLA707857811.537.76097.29
384241913/1/2024 0:00BOBBY RUMOREWDHH8M0AHSHELL NORCO10022597-NAVY-MEDRMNS FR AIR HENLEY LS TOP NAVYRacelandLA70394728.8620.7341.5960
484241913/1/2024 0:00BOBBY RUMOREWDHH8M0AHSHELL NORCO10022599-GRAY-MEDRMNS FR AIR HENLEY LS TOP SILVRRacelandLA703947272
584241913/1/2024 0:00BOBBY RUMOREWDHH8M0AHSHELL NORCO10022597-NAVY-MEDRMNS FR AIR HENLEY LS TOP NAVYRacelandLA703947272
684256833/1/2024 0:00BRANDON GONZALEZ7Q6LCEJNBGOLDEN PASS LNG10023466-BLUE-2932MNS FR M4 RLX STR DLT BSC BT CPort ArthurTX776422069.1317.7511.37221.51
784253053/1/2024 0:00GUILLERMO MENDOZA2B6MZVIMTCARSONP-INDM10 42X3042x30 10OZ FR MODERN JEANSLONG BEACHCA908055928.140087.14
884253053/1/2024 0:00GUILLERMO MENDOZA2B6MZVIMTCARSON888830073032Rambler 36oz Bottle Chug NavyLONG BEACHCA90805590059
984253053/1/2024 0:00GUILLERMO MENDOZA2B6MZVIMTCARSON10023466-BLUE-4230MNS FR M4 Relaxed Stretch DuraLONG BEACHCA9080510300103
1084253053/1/2024 0:00GUILLERMO MENDOZA2B6MZVIMTCARSON10012258-GRAY-3XLTRMNS FR Work Crew T-ShirtLONG BEACHCA90805830083
1184324433/1/2024 0:00ANDREW GARCIA5UASCACLJCITGO306-396-XLTahoeMISSIONTX785744011.64.26055.86
1284308203/1/2024 0:00SHALTON LOPEZ-GARCIABMFBSK7ORGBR8051-33BKHigh Sierra Elite Fly-By 17 inNORTH BRUNSWNJ08902789.8503.2184.64
AR_Bartlett
Cell Formulas
RangeFormula
P2:P12P2=SUM(AR_Bartlett[@[ExtensionAmt]:[SalesTaxAmt]])-[@DepositAmt]
 
Thanks for the XL2BB sample. That has shown that the issue affecting my formula is that some of the "empty" cells in column O are not empty but contain space characters. Those cells are shown in yellow below. There are also space characters in the blue cells though they do not cause a problem in my formula.

To me, the ideal solution would be to clean up the original data so that such space characters are removed (yellow and blue) as that sort of thing often affects later results and is not obvious to look at.
Failing that, if you wanted to use a structured refence formula for the "Net Invoice" column, once the data is in this table you could either
  • Find/Replace space characters in those columns, or at least column O, (with 'Match entire cell contents' set) and my previous formula should work
    or
  • Leave those space characters alone and slightly change my formula as follows

    =LET(SO,[@SalesOrderNo],d,FILTER(AR_Bartlett[[ExtensionAmt]:[DepositAmt]],[SalesOrderNo]=SO),IF(SO=OFFSET(SO,-1,0),"",SUM(TAKE(d,,3),-N(TAKE(d,,-1)))))
Here it is with those space characters still in the yellow (& blue) cells.

jarett.xlsm
BLMNOP
1SalesOrderNoExtensionAmtFreightAmtSalesTaxAmtDepositAmtNet Invoice
284323107811.537.76097.29
38424191728.8620.7341.59204
4842419172 
5842419172 
684256832069.1317.7511.37221.51
784253055928.1400332.14
884253055900 
9842530510300 
1084253058300 
1184324434011.64.26055.86
128430820789.8503.2184.64
1384202996821.4302.43290
1484202991000 
158420299350 
16842029968 0  
178425805729.4412.050152.49
188425805590 
19843332310012.459.9517.4105
20843230320610.4517.860234.31
21842776415212.4513.980178.43
228429684799.5227.690330.21
23842968478 0 
24842968418 0 
258429684118 0 
268427981688.8612.280161.14
27842798172 0 
288407581619.316.114.59186.82
29840758168  
30840758137  
Sheet4
Cell Formulas
RangeFormula
P2:P30P2=LET(SO,[@SalesOrderNo],d,FILTER(AR_Bartlett[[ExtensionAmt]:[DepositAmt]],[SalesOrderNo]=SO),IF(SO=OFFSET(SO,-1,0),"",SUM(TAKE(d,,3),-N(TAKE(d,,-1)))))
As I mentioned to a previous post, my data is not true, I refreshed the spreadsheet today and it does not have any blank cells, there is a value in each one. The lines with one record are calculating correctly. Records with multiple records are off, it loooks like they are summing all values in M, N, and subtracting all values from the sum of O. I just need the first value because they are repeating, or should I figure out how to remove those "duplicate" values before it even gets to the formula? I tried both versions of your LET formula @Peter_SSs and neither output the correct values when I corrected the data. This sample data set is fresh and the value in column S is what P2 should equal. P14 is the only cell that calculated correctly.
AR_Bartlett_COPY.xlsx
ALMNOPQRS
1InvoiceNoExtensionAmtFreightAmtSalesTaxAmtDepositAmtNet Invoice231.63
20056404358.8618.770286.89
30056404788.8618.770 
40056404918.8618.770 
5005640626115.4802.48416
600564067915.4802.48 
700564063715.4802.48 
80056408798.7314.450203.36
90056408788.7314.450 
100056409751115.020203.04
110056409761115.020 
1200564103910.3400159.68
13005641010010.3400 
140056411428.254.15054.4
150056412013.3523.6315.87357.44
16005641215413.3523.6315.87 
1700564127713.3523.6315.87 
1800564124213.3523.6315.87 
AR_Bartlett
Cell Formulas
RangeFormula
P2:P18P2=IF(A2=A1,"",SUMIF(A:A,A2,L:L)+SUMIF(A:A,A2,M:M)+SUMIF(A:A,A2,N:N)-SUMIF(A:A,A2,O:O))
Named Ranges
NameRefers ToCells
ExternalData_1=AR_Bartlett!$A$1:$O$290P2:P18
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this modification:
Excel Formula:
=IF(A2=A1,"",SUMIF(A:A,A2,L:L)+(M2+N2)-O2)
 
Upvote 0
Try this modification:
Excel Formula:
=IF(A2=A1,"",SUMIF(A:A,A2,L:L)+(M2+N2)-O2)
Inputted into data and everything looks good so far, will check it again when we have to refresh in another week or so.
 
Upvote 0
I tried both versions of your LET formula @Peter_SSs and neither output the correct values when I corrected the data.
No, that's because your data structure & requirement is quite different to what you had posted earlier.
This amendment to my structured reference-style formula gives the same results as the SUMIF suggestion in post 12 for the sample data provided.

Excel Formula:
=LET(SO,[@InvoiceNo],d,FILTER(AR_Bartlett[[ExtensionAmt]:[DepositAmt]],[InvoiceNo]=SO),IF(SO=OFFSET(SO,-1,0),"",SUM(TAKE(d,,1),TAKE(d,1)*{0,1,1,-1})))

However, given the changed structure I would recommend the SUMIF approach over this as it is a more efficient calculation (as well as shorter formula of course. :))

A very minor point but the SUMIF suggestion does have one set of parentheses that are not needed.

Excel Formula:
=IF(A2=A1,"",SUMIF(A:A,A2,L:L)+M2+N2-O2)
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top