LIFOtvf
Updated 2023-10-12 14:25:00.540000
Syntax
SELECT * FROM [westclintech].[wct].[LIFOtvf] (
<@DataQuery, nvarchar(max),>)
Description
Use the SQL Server table-valued function LIFOtvf to calculate running LIFO (Last In, First Out) values in an ordered resultant table. LIFOtvf calculates balances for each value from the first value to the last value in the ordered group or partition. LIFOtvf returns:
• quantity on-hand
• inventory cost
• cost of goods sold
• gross margin on sale
• gross margin percentage
• average inventory price
• last inventory price
• cumulative cost of goods sold
• cumulative gross margin on sale
• cumulative gross margin percentage.
LIFOtvf supports both long and short inventory positions. In other words, if the quantity on hand falls below the zero, LIFOtvf calculates from the last sale or withdrawal transaction, rather than from the last purchases or additions to inventory.
LIFOtvf assumes that the quantity (i.e. the number of units) of the transaction and the monetary value of the transaction have the same sign. LIFOtvf adds NULL values to the inventory at the last price.
LIFOtvf requires monotonically ascending row numbers within a partition.
LIFOtvf resets all calculated values when the row number value is 1.
Arguments
@DataQuery
An SQL statement which returns a resultant table containing the unique transaction identifier, ROW_NUMBER(), quantity and amount.
Return Type
table
{"columns": [{"field": "colName", "headerName": "Name", "header": "name"}, {"field": "colDatatype", "headerName": "Type", "header": "type"}, {"field": "colDesc", "headerName": "Description", "header": "description", "minWidth": 1000}], "rows": [{"id": "4682108c-eba6-453a-8e3e-05d12454f090", "colName": "ID", "colDatatype": "sql_variant", "colDesc": "unique transaction identifier"}, {"id": "a7a8101d-2c4d-447b-ab99-c46191a6b821", "colName": "QTY", "colDatatype": "float", "colDesc": "inventory quantity"}, {"id": "82282587-2672-4eee-88a1-26eaf278a87e", "colName": "EB", "colDatatype": "float", "colDesc": "inventory value"}, {"id": "d94be12e-f5a0-44de-88a1-60d74c333f79", "colName": "GM", "colDatatype": "float", "colDesc": "gross margin on sale"}, {"id": "bc90d042-1367-4933-a677-f2f859462005", "colName": "COGS", "colDatatype": "float", "colDesc": "cost of goods sold"}, {"id": "39cd2136-dba1-4ebd-b706-d5214f92df47", "colName": "UP", "colDatatype": "float", "colDesc": "unit price"}, {"id": "f5b2df27-c8f0-4204-8168-f075667299dd", "colName": "LP", "colDatatype": "float", "colDesc": "last item-added price"}, {"id": "e7293445-4517-450c-b999-9af27fb996a3", "colName": "COGSC", "colDatatype": "float", "colDesc": "cumulative cost-of-goods-sold"}, {"id": "1c24e90d-f5af-4396-a95a-088eb9372091", "colName": "GMC", "colDatatype": "float", "colDesc": "cumulative gross margin"}, {"id": "e77b5f23-dc42-4758-923c-9b52dbbdeb2e", "colName": "GMP", "colDatatype": "float", "colDesc": "gross margin percentage"}, {"id": "abc7ddbe-ce71-49a8-a1d8-5bdb1a267810", "colName": "CGMP", "colDatatype": "float", "colDesc": "cumulative gross margin percentage"}]}
Remarks
If the 3rd column (quantity) of the resultant table from @DataQuery contains NULL an error will be generated.
This function relies on the SQL Server ROW_NUMBER() function and expects results to be returned in ascending ROW_NUMBER() order within a PARTITION.
When ROW_NUMBER() = 1 all inventory values are re-initialized.
Examples
Example #1
In the following examples, we calculate LIFO inventory values for stock trades in the ABC, XYZ, and GHI companies. We will create a temporary table, #c and populate it with some data. We can be either short or long the shares at any point in time.
--Create the temporary table
CREATE TABLE #c
(
trn int,
sym char(3),
tDate date,
qty money,
price_unit money,
price_extended money,
PRIMARY KEY (trn)
);
--Populate the table with some data
INSERT INTO #c
VALUES
(01131019, 'XYZ', '2013-10-19', 424, 25.13, 10655.12);
INSERT INTO #c
VALUES
(02130617, 'ABC', '2013-06-17', 313, 12.93, 4047.09);
INSERT INTO #c
VALUES
(03130308, 'ABC', '2013-03-08', -157, 13.17, -2067.69);
INSERT INTO #c
VALUES
(04130516, 'GHI', '2013-05-16', 160, 34.48, 5516.8);
INSERT INTO #c
VALUES
(05130706, 'XYZ', '2013-07-06', -170, 23.46, -3988.2);
INSERT INTO #c
VALUES
(06130924, 'GHI', '2013-09-24', 328, 34.95, 11463.6);
INSERT INTO #c
VALUES
(07130722, 'ABC', '2013-07-22', 599, 13.65, 8176.35);
INSERT INTO #c
VALUES
(08131231, 'ABC', '2013-12-31', -145, 13.19, -1912.55);
INSERT INTO #c
VALUES
(09131025, 'XYZ', '2013-10-25', -153, 24.31, -3719.43);
INSERT INTO #c
VALUES
(10130908, 'ABC', '2013-09-08', -386, 13.65, -5268.9);
INSERT INTO #c
VALUES
(11130906, 'XYZ', '2013-09-06', -13, 23.97, -311.61);
INSERT INTO #c
VALUES
(12130621, 'ABC', '2013-06-21', -326, 12.73, -4149.98);
INSERT INTO #c
VALUES
(13131221, 'GHI', '2013-12-21', 72, 34.38, 2475.36);
INSERT INTO #c
VALUES
(14130705, 'XYZ', '2013-07-05', -277, 25.01, -6927.77);
INSERT INTO #c
VALUES
(15130307, 'GHI', '2013-03-07', 559, 35.21, 19682.39);
INSERT INTO #c
VALUES
(16131107, 'ABC', '2013-11-07', 27, 12.68, 342.36);
INSERT INTO #c
VALUES
(17130924, 'GHI', '2013-09-24', -291, 35.69, -10385.79);
INSERT INTO #c
VALUES
(18140125, 'GHI', '2014-01-25', -78, 35.46, -2765.88);
INSERT INTO #c
VALUES
(19130516, 'XYZ', '2013-05-16', 315, 23.57, 7424.55);
INSERT INTO #c
VALUES
(20130518, 'ABC', '2013-05-18', 298, 13.23, 3942.54);
INSERT INTO #c
VALUES
(21131103, 'XYZ', '2013-11-03', -326, 23.24, -7576.24);
INSERT INTO #c
VALUES
(22131012, 'XYZ', '2013-10-12', 596, 23.16, 13803.36);
INSERT INTO #c
VALUES
(23130619, 'XYZ', '2013-06-19', 296, 23.46, 6944.16);
INSERT INTO #c
VALUES
(24130418, 'XYZ', '2013-04-18', 275, 24.83, 6828.25);
INSERT INTO #c
VALUES
(25130408, 'ABC', '2013-04-08', 298, 12.98, 3868.04);
INSERT INTO #c
VALUES
(26130320, 'ABC', '2013-03-20', -92, 13.64, -1254.88);
INSERT INTO #c
VALUES
(27130906, 'XYZ', '2013-09-06', -147, 23.81, -3500.07);
INSERT INTO #c
VALUES
(28131209, 'XYZ', '2013-12-09', 315, 24.46, 7704.9);
INSERT INTO #c
VALUES
(29130602, 'XYZ', '2013-06-02', 114, 24.29, 2769.06);
INSERT INTO #c
VALUES
(30130519, 'XYZ', '2013-05-19', 467, 23.15, 10811.05);
INSERT INTO #c
VALUES
(31140205, 'XYZ', '2014-02-05', 42, 24.39, 1024.38);
INSERT INTO #c
VALUES
(32130310, 'ABC', '2013-03-10', -63, 12.61, -794.43);
INSERT INTO #c
VALUES
(33140102, 'XYZ', '2014-01-02', -196, 22.98, -4504.08);
INSERT INTO #c
VALUES
(34130507, 'XYZ', '2013-05-07', 55, 23.43, 1288.65);
INSERT INTO #c
VALUES
(35130321, 'XYZ', '2013-03-21', 275, 24.83, 6828.25);
INSERT INTO #c
VALUES
(36130917, 'XYZ', '2013-09-17', 92, 24.6, 2263.2);
INSERT INTO #c
VALUES
(37130220, 'XYZ', '2013-02-20', 528, 23.54, 12429.12);
INSERT INTO #c
VALUES
(38130311, 'XYZ', '2013-03-11', -193, 24.9, -4805.7);
INSERT INTO #c
VALUES
(39130908, 'ABC', '2013-09-08', 490, 12.69, 6218.1);
INSERT INTO #c
VALUES
(40131013, 'XYZ', '2013-10-13', 359, 23.91, 8583.69);
INSERT INTO #c
VALUES
(41130310, 'ABC', '2013-03-10', 463, 13.38, 6194.94);
INSERT INTO #c
VALUES
(42131011, 'XYZ', '2013-10-11', -250, 23.12, -5780);
INSERT INTO #c
VALUES
(43130521, 'GHI', '2013-05-21', -174, 34.2, -5950.8);
INSERT INTO #c
VALUES
(44130227, 'XYZ', '2013-02-27', 357, 22.86, 8161.02);
INSERT INTO #c
VALUES
(45131030, 'XYZ', '2013-10-30', -350, 23.36, -8176);
INSERT INTO #c
VALUES
(46130301, 'ABC', '2013-03-01', 157, 13.01, 2042.57);
INSERT INTO #c
VALUES
(47130619, 'XYZ', '2013-06-19', 413, 25.18, 10399.34);
INSERT INTO #c
VALUES
(48130430, 'ABC', '2013-04-30', 229, 13.32, 3050.28);
INSERT INTO #c
VALUES
(49130508, 'ABC', '2013-05-08', 238, 12.79, 3044.02);
INSERT INTO #c
VALUES
(50131103, 'GHI', '2013-11-03', -246, 35.61, -8760.06);
INSERT INTO #c
VALUES
(51131206, 'GHI', '2013-12-06', 85, 33.64, 2859.4);
INSERT INTO #c
VALUES
(52131014, 'GHI', '2013-10-14', -91, 33.12, -3013.92);
INSERT INTO #c
VALUES
(53140102, 'GHI', '2014-01-02', 396, 35.52, 14065.92);
INSERT INTO #c
VALUES
(54130831, 'XYZ', '2013-08-31', -61, 23.23, -1417.03);
INSERT INTO #c
VALUES
(55130630, 'XYZ', '2013-06-30', -272, 23.45, -6378.4);
INSERT INTO #c
VALUES
(56130419, 'GHI', '2013-04-19', 416, 34.46, 14335.36);
INSERT INTO #c
VALUES
(57130813, 'XYZ', '2013-08-13', -163, 23.65, -3854.95);
INSERT INTO #c
VALUES
(58130722, 'XYZ', '2013-07-22', -88, 24.64, -2168.32);
INSERT INTO #c
VALUES
(59130320, 'XYZ', '2013-03-20', -20, 23.59, -471.8);
INSERT INTO #c
VALUES
(60130419, 'XYZ', '2013-04-19', 277, 22.83, 6323.91);
INSERT INTO #c
VALUES
(61130916, 'ABC', '2013-09-16', -202, 12.94, -2613.88);
INSERT INTO #c
VALUES
(62131027, 'XYZ', '2013-10-27', -248, 24.71, -6128.08);
INSERT INTO #c
VALUES
(63130806, 'GHI', '2013-08-06', 445, 33.5, 14907.5);
INSERT INTO #c
VALUES
(64140109, 'XYZ', '2014-01-09', -253, 24.46, -6188.38);
INSERT INTO #c
VALUES
(65131227, 'GHI', '2013-12-27', 376, 33.49, 12592.24);
INSERT INTO #c
VALUES
(66140203, 'XYZ', '2014-02-03', 459, 23.7, 10878.3);
INSERT INTO #c
VALUES
(67130302, 'XYZ', '2013-03-02', 9, 24.04, 216.36);
INSERT INTO #c
VALUES
(68130223, 'ABC', '2013-02-23', 238, 12.78, 3041.64);
INSERT INTO #c
VALUES
(69130403, 'GHI', '2013-04-03', -151, 33.16, -5007.16);
INSERT INTO #c
VALUES
(70130702, 'GHI', '2013-07-02', -162, 35.48, -5747.76);
INSERT INTO #c
VALUES
(71130731, 'ABC', '2013-07-31', 79, 13.55, 1070.45);
INSERT INTO #c
VALUES
(72140204, 'XYZ', '2014-02-04', -208, 24.36, -5066.88);
INSERT INTO #c
VALUES
(73131028, 'GHI', '2013-10-28', -46, 34.65, -1593.9);
INSERT INTO #c
VALUES
(74130619, 'XYZ', '2013-06-19', 202, 22.95, 4635.9);
INSERT INTO #c
VALUES
(75131216, 'GHI', '2013-12-16', 500, 33.55, 16775);
INSERT INTO #c
VALUES
(76131009, 'ABC', '2013-10-09', 249, 13.47, 3354.03);
INSERT INTO #c
VALUES
(77130825, 'GHI', '2013-08-25', 272, 33.86, 9209.92);
INSERT INTO #c
VALUES
(78140112, 'XYZ', '2014-01-12', 332, 24.28, 8060.96);
INSERT INTO #c
VALUES
(79131223, 'XYZ', '2013-12-23', -376, 25.12, -9445.12);
INSERT INTO #c
VALUES
(80140126, 'XYZ', '2014-01-26', 404, 24.23, 9788.92);
INSERT INTO #c
VALUES
(81131123, 'GHI', '2013-11-23', 187, 33.86, 6331.82);
INSERT INTO #c
VALUES
(82140131, 'XYZ', '2014-01-31', 548, 23.65, 12960.2);
INSERT INTO #c
VALUES
(83130428, 'XYZ', '2013-04-28', 142, 23.13, 3284.46);
INSERT INTO #c
VALUES
(84140104, 'XYZ', '2014-01-04', 261, 24.46, 6384.06);
INSERT INTO #c
VALUES
(85131002, 'GHI', '2013-10-02', -295, 32.51, -9590.45);
INSERT INTO #c
VALUES
(86131114, 'ABC', '2013-11-14', -386, 12.4, -4786.4);
INSERT INTO #c
VALUES
(87131116, 'GHI', '2013-11-16', -320, 34.16, -10931.2);
INSERT INTO #c
VALUES
(88131009, 'ABC', '2013-10-09', 187, 13.36, 2498.32);
INSERT INTO #c
VALUES
(89130611, 'ABC', '2013-06-11', 130, 13.02, 1692.6);
INSERT INTO #c
VALUES
(90130430, 'ABC', '2013-04-30', -191, 13.49, -2576.59);
INSERT INTO #c
VALUES
(91130615, 'XYZ', '2013-06-15', 545, 23.88, 13014.6);
INSERT INTO #c
VALUES
(92130924, 'XYZ', '2013-09-24', -248, 24.58, -6095.84);
INSERT INTO #c
VALUES
(93130622, 'ABC', '2013-06-22', -227, 13.47, -3057.69);
INSERT INTO #c
VALUES
(94131117, 'GHI', '2013-11-17', -92, 32.65, -3003.8);
INSERT INTO #c
VALUES
(95130908, 'GHI', '2013-09-08', 103, 35.42, 3648.26);
INSERT INTO #c
VALUES
(96130716, 'GHI', '2013-07-16', -347, 35.29, -12245.63);
INSERT INTO #c
VALUES
(97131125, 'XYZ', '2013-11-25', -278, 23.18, -6444.04);
INSERT INTO #c
VALUES
(98130413, 'XYZ', '2013-04-13', 243, 24.25, 5892.75);
INSERT INTO #c
VALUES
(99130515, 'XYZ', '2013-05-15', 97, 25.13, 2437.61);
--Calculate the LIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #lifo
FROM wct.LIFOtvf('SELECT trn, ROW_NUMBER() OVER (PARTITION by sym ORDER BY sym,
tDate, trn),qty,price_extended FROM #c ORDER BY sym, tDate, trn');
--JOIN to the source data to produce the inventory output
SELECT c.trn,
c.sym,
c.tDate,
c.qty,
c.price_unit,
c.price_extended,
l.[QTY] as [Inventory-On-Hand],
l.[EB] as [Inventory Cost],
l.[GM] as [Gross Margin on Sales],
l.[COGS] as [Cost-of-Goods Sold],
l.[UP] as [Average Price],
l.[LP] as [Last Price],
l.[COGSC] as [Cumulative COGS],
l.[GMC] as [Cumulative Gross Margin],
l.[GMP] as [GM Percentage],
l.[CGMP] as [Cumulative GM Percentage]
FROM #c c
INNER JOIN #LIFO l
ON c.trn = l.[ID]
ORDER BY c.sym,
c.tDate,
c.trn;
This produces the following result.
{"columns":[{"field":"trn","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"sym"},{"field":"tDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"qty","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"price_unit","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"price_extended","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory-On-Hand","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory Cost","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Gross Margin on Sales","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cost-of-Goods Sold","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Average Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Last Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative COGS","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative Gross Margin","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GM Percentage"},{"field":"Cumulative GM Percentage"}],"rows":[{"trn":"68130223","sym":"ABC","tDate":"2013-02-23","qty":"238.00","price_unit":"12.78","price_extended":"3041.64","Inventory-On-Hand":"238","Inventory Cost":"3041.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"12.78","Last Price":"12.78","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"46130301","sym":"ABC","tDate":"2013-03-01","qty":"157.00","price_unit":"13.01","price_extended":"2042.57","Inventory-On-Hand":"395","Inventory Cost":"5084.21","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"12.871417721519","Last Price":"13.01","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"3130308","sym":"ABC","tDate":"2013-03-08","qty":"-157.00","price_unit":"13.17","price_extended":"-2067.69","Inventory-On-Hand":"238","Inventory Cost":"3041.64","Gross Margin on Sales":"25.1199999999999","Cost-of-Goods Sold":"-2042.57","Average Price":"12.78","Last Price":"13.01","Cumulative COGS":"-2042.57","Cumulative Gross Margin":"25.1199999999999","GM Percentage":"0.0121488230827638","Cumulative GM Percentage":"0.0121488230827638"},{"trn":"32130310","sym":"ABC","tDate":"2013-03-10","qty":"-63.00","price_unit":"12.61","price_extended":"-794.43","Inventory-On-Hand":"175","Inventory Cost":"2236.5","Gross Margin on Sales":"-10.7099999999999","Cost-of-Goods Sold":"-805.14","Average Price":"12.78","Last Price":"13.01","Cumulative COGS":"-2847.71","Cumulative Gross Margin":"14.41","GM Percentage":"-0.0134813639968278","Cumulative GM Percentage":"0.00503472950120888"},{"trn":"41130310","sym":"ABC","tDate":"2013-03-10","qty":"463.00","price_unit":"13.38","price_extended":"6194.94","Inventory-On-Hand":"638","Inventory Cost":"8431.44","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2154231974922","Last Price":"13.38","Cumulative COGS":"-2847.71","Cumulative Gross Margin":"14.41","GM Percentage":"NULL","Cumulative GM Percentage":"0.00503472950120888"},{"trn":"26130320","sym":"ABC","tDate":"2013-03-20","qty":"-92.00","price_unit":"13.64","price_extended":"-1254.88","Inventory-On-Hand":"546","Inventory Cost":"7200.48","Gross Margin on Sales":"23.920000000001","Cost-of-Goods Sold":"-1230.96","Average Price":"13.1876923076923","Last Price":"13.38","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"0.0190615835777134","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"25130408","sym":"ABC","tDate":"2013-04-08","qty":"298.00","price_unit":"12.98","price_extended":"3868.04","Inventory-On-Hand":"844","Inventory Cost":"11068.52","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1143601895735","Last Price":"12.98","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"48130430","sym":"ABC","tDate":"2013-04-30","qty":"229.00","price_unit":"13.32","price_extended":"3050.28","Inventory-On-Hand":"1073","Inventory Cost":"14118.8","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1582479030755","Last Price":"13.32","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"90130430","sym":"ABC","tDate":"2013-04-30","qty":"-191.00","price_unit":"13.49","price_extended":"-2576.59","Inventory-On-Hand":"882","Inventory Cost":"11574.68","Gross Margin on Sales":"32.4699999999993","Cost-of-Goods Sold":"-2544.12","Average Price":"13.1232199546485","Last Price":"13.32","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"0.012601927353595","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"49130508","sym":"ABC","tDate":"2013-05-08","qty":"238.00","price_unit":"12.79","price_extended":"3044.02","Inventory-On-Hand":"1120","Inventory Cost":"14618.7","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0524107142857","Last Price":"12.79","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"20130518","sym":"ABC","tDate":"2013-05-18","qty":"298.00","price_unit":"13.23","price_extended":"3942.54","Inventory-On-Hand":"1418","Inventory Cost":"18561.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0897320169252","Last Price":"13.23","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"89130611","sym":"ABC","tDate":"2013-06-11","qty":"130.00","price_unit":"13.02","price_extended":"1692.60","Inventory-On-Hand":"1548","Inventory Cost":"20253.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0838759689922","Last Price":"13.02","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"2130617","sym":"ABC","tDate":"2013-06-17","qty":"313.00","price_unit":"12.93","price_extended":"4047.09","Inventory-On-Hand":"1861","Inventory Cost":"24300.93","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0579957012359","Last Price":"12.93","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"12130621","sym":"ABC","tDate":"2013-06-21","qty":"-326.00","price_unit":"12.73","price_extended":"-4149.98","Inventory-On-Hand":"1535","Inventory Cost":"20084.58","Gross Margin on Sales":"-66.369999999999","Cost-of-Goods Sold":"-4216.35","Average Price":"13.0844169381108","Last Price":"12.93","Cumulative COGS":"-10839.14","Cumulative Gross Margin":"4.43000000000131","GM Percentage":"-0.0159928481583041","Cumulative GM Percentage":"0.000408537040845525"},{"trn":"93130622","sym":"ABC","tDate":"2013-06-22","qty":"-227.00","price_unit":"13.47","price_extended":"-3057.69","Inventory-On-Hand":"1308","Inventory Cost":"17105.94","Gross Margin on Sales":"79.0500000000006","Cost-of-Goods Sold":"-2978.64","Average Price":"13.0779357798165","Last Price":"12.93","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"0.0258528497002641","Cumulative GM Percentage":"0.006005211038424"},{"trn":"7130722","sym":"ABC","tDate":"2013-07-22","qty":"599.00","price_unit":"13.65","price_extended":"8176.35","Inventory-On-Hand":"1907","Inventory Cost":"25282.29","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2576245411641","Last Price":"13.65","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"NULL","Cumulative GM Percentage":"0.006005211038424"},{"trn":"71130731","sym":"ABC","tDate":"2013-07-31","qty":"79.00","price_unit":"13.55","price_extended":"1070.45","Inventory-On-Hand":"1986","Inventory Cost":"26352.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2692547834844","Last Price":"13.55","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"NULL","Cumulative GM Percentage":"0.006005211038424"},{"trn":"10130908","sym":"ABC","tDate":"2013-09-08","qty":"-386.00","price_unit":"13.65","price_extended":"-5268.90","Inventory-On-Hand":"1600","Inventory Cost":"21091.74","Gross Margin on Sales":"7.89999999999964","Cost-of-Goods Sold":"-5261","Average Price":"13.1823375","Last Price":"13.55","Cumulative COGS":"-19078.78","Cumulative Gross Margin":"91.3800000000016","GM Percentage":"0.00149936419366464","Cumulative GM Percentage":"0.00476678337583002"},{"trn":"39130908","sym":"ABC","tDate":"2013-09-08","qty":"490.00","price_unit":"12.69","price_extended":"6218.10","Inventory-On-Hand":"2090","Inventory Cost":"27309.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0669090909091","Last Price":"12.69","Cumulative COGS":"-19078.78","Cumulative Gross Margin":"91.3800000000016","GM Percentage":"NULL","Cumulative GM Percentage":"0.00476678337583002"},{"trn":"61130916","sym":"ABC","tDate":"2013-09-16","qty":"-202.00","price_unit":"12.94","price_extended":"-2613.88","Inventory-On-Hand":"1888","Inventory Cost":"24746.46","Gross Margin on Sales":"50.4999999999991","Cost-of-Goods Sold":"-2563.38","Average Price":"13.1072351694915","Last Price":"12.69","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"0.0193199381761975","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"76131009","sym":"ABC","tDate":"2013-10-09","qty":"249.00","price_unit":"13.47","price_extended":"3354.03","Inventory-On-Hand":"2137","Inventory Cost":"28100.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1495039775386","Last Price":"13.47","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"88131009","sym":"ABC","tDate":"2013-10-09","qty":"187.00","price_unit":"13.36","price_extended":"2498.32","Inventory-On-Hand":"2324","Inventory Cost":"30598.81","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1664414802065","Last Price":"13.36","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"16131107","sym":"ABC","tDate":"2013-11-07","qty":"27.00","price_unit":"12.68","price_extended":"342.36","Inventory-On-Hand":"2351","Inventory Cost":"30941.17","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1608549553382","Last Price":"12.68","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"86131114","sym":"ABC","tDate":"2013-11-14","qty":"-386.00","price_unit":"12.40","price_extended":"-4786.40","Inventory-On-Hand":"1965","Inventory Cost":"25783.65","Gross Margin on Sales":"-371.120000000001","Cost-of-Goods Sold":"-5157.52","Average Price":"13.1214503816794","Last Price":"12.68","Cumulative COGS":"-26799.68","Cumulative Gross Margin":"-229.24","GM Percentage":"-0.0775363530001673","Cumulative GM Percentage":"-0.00862763281300574"},{"trn":"8131231","sym":"ABC","tDate":"2013-12-31","qty":"-145.00","price_unit":"13.19","price_extended":"-1912.55","Inventory-On-Hand":"1820","Inventory Cost":"23883.54","Gross Margin on Sales":"12.4399999999994","Cost-of-Goods Sold":"-1900.11","Average Price":"13.1228241758242","Last Price":"12.68","Cumulative COGS":"-28699.79","Cumulative Gross Margin":"-216.800000000001","GM Percentage":"0.00650440511359147","Cumulative GM Percentage":"-0.00761156044361918"},{"trn":"15130307","sym":"GHI","tDate":"2013-03-07","qty":"559.00","price_unit":"35.21","price_extended":"19682.39","Inventory-On-Hand":"559","Inventory Cost":"19682.39","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"35.21","Last Price":"35.21","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"69130403","sym":"GHI","tDate":"2013-04-03","qty":"-151.00","price_unit":"33.16","price_extended":"-5007.16","Inventory-On-Hand":"408","Inventory Cost":"14365.68","Gross Margin on Sales":"-309.549999999999","Cost-of-Goods Sold":"-5316.71","Average Price":"35.21","Last Price":"35.21","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"-0.0618214716525933","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"56130419","sym":"GHI","tDate":"2013-04-19","qty":"416.00","price_unit":"34.46","price_extended":"14335.36","Inventory-On-Hand":"824","Inventory Cost":"28701.04","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.831359223301","Last Price":"34.46","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"4130516","sym":"GHI","tDate":"2013-05-16","qty":"160.00","price_unit":"34.48","price_extended":"5516.80","Inventory-On-Hand":"984","Inventory Cost":"34217.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.7742276422764","Last Price":"34.48","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"43130521","sym":"GHI","tDate":"2013-05-21","qty":"-174.00","price_unit":"34.20","price_extended":"-5950.80","Inventory-On-Hand":"810","Inventory Cost":"28218.6","Gross Margin on Sales":"-48.4400000000051","Cost-of-Goods Sold":"-5999.24000000001","Average Price":"34.8377777777778","Last Price":"34.48","Cumulative COGS":"-11315.95","Cumulative Gross Margin":"-357.990000000004","GM Percentage":"-0.00814008200578159","Cumulative GM Percentage":"-0.03266940196898"},{"trn":"70130702","sym":"GHI","tDate":"2013-07-02","qty":"-162.00","price_unit":"35.48","price_extended":"-5747.76","Inventory-On-Hand":"648","Inventory Cost":"22636.08","Gross Margin on Sales":"165.240000000003","Cost-of-Goods Sold":"-5582.52","Average Price":"34.9322222222222","Last Price":"34.48","Cumulative COGS":"-16898.47","Cumulative Gross Margin":"-192.750000000001","GM Percentage":"0.0287485907553557","Cumulative GM Percentage":"-0.0115379642421878"},{"trn":"96130716","sym":"GHI","tDate":"2013-07-16","qty":"-347.00","price_unit":"35.29","price_extended":"-12245.63","Inventory-On-Hand":"301","Inventory Cost":"10598.21","Gross Margin on Sales":"207.759999999998","Cost-of-Goods Sold":"-12037.87","Average Price":"35.21","Last Price":"34.48","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"0.0169660523795018","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"63130806","sym":"GHI","tDate":"2013-08-06","qty":"445.00","price_unit":"33.50","price_extended":"14907.50","Inventory-On-Hand":"746","Inventory Cost":"25505.71","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1899597855228","Last Price":"33.5","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"77130825","sym":"GHI","tDate":"2013-08-25","qty":"272.00","price_unit":"33.86","price_extended":"9209.92","Inventory-On-Hand":"1018","Inventory Cost":"34715.63","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1017976424361","Last Price":"33.86","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"95130908","sym":"GHI","tDate":"2013-09-08","qty":"103.00","price_unit":"35.42","price_extended":"3648.26","Inventory-On-Hand":"1121","Inventory Cost":"38363.89","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.2229170383586","Last Price":"35.42","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"6130924","sym":"GHI","tDate":"2013-09-24","qty":"328.00","price_unit":"34.95","price_extended":"11463.60","Inventory-On-Hand":"1449","Inventory Cost":"49827.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.3875017253278","Last Price":"34.95","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"17130924","sym":"GHI","tDate":"2013-09-24","qty":"-291.00","price_unit":"35.69","price_extended":"-10385.79","Inventory-On-Hand":"1158","Inventory Cost":"39657.04","Gross Margin on Sales":"215.340000000004","Cost-of-Goods Sold":"-10170.45","Average Price":"34.2461485319516","Last Price":"34.95","Cumulative COGS":"-39106.79","Cumulative Gross Margin":"230.350000000001","GM Percentage":"0.0207340991874478","Cumulative GM Percentage":"0.0058557892109086"},{"trn":"85131002","sym":"GHI","tDate":"2013-10-02","qty":"-295.00","price_unit":"32.51","price_extended":"-9590.45","Inventory-On-Hand":"863","Inventory Cost":"29467.33","Gross Margin on Sales":"-599.260000000002","Cost-of-Goods Sold":"-10189.71","Average Price":"34.1452259559676","Last Price":"34.95","Cumulative COGS":"-49296.5","Cumulative Gross Margin":"-368.910000000001","GM Percentage":"-0.062485076299861","Cumulative GM Percentage":"-0.00753991766199808"},{"trn":"52131014","sym":"GHI","tDate":"2013-10-14","qty":"-91.00","price_unit":"33.12","price_extended":"-3013.92","Inventory-On-Hand":"772","Inventory Cost":"26386.07","Gross Margin on Sales":"-67.3399999999983","Cost-of-Goods Sold":"-3081.26","Average Price":"34.1788471502591","Last Price":"34.95","Cumulative COGS":"-52377.76","Cumulative Gross Margin":"-436.249999999999","GM Percentage":"-0.0223429951690816","Cumulative GM Percentage":"-0.00839887019072028"},{"trn":"73131028","sym":"GHI","tDate":"2013-10-28","qty":"-46.00","price_unit":"34.65","price_extended":"-1593.90","Inventory-On-Hand":"726","Inventory Cost":"24835.71","Gross Margin on Sales":"43.5399999999995","Cost-of-Goods Sold":"-1550.36","Average Price":"34.2089669421488","Last Price":"34.95","Cumulative COGS":"-53928.12","Cumulative Gross Margin":"-392.71","GM Percentage":"0.0273166447079487","Cumulative GM Percentage":"-0.00733551867819822"},{"trn":"50131103","sym":"GHI","tDate":"2013-11-03","qty":"-246.00","price_unit":"35.61","price_extended":"-8760.06","Inventory-On-Hand":"480","Inventory Cost":"16594.71","Gross Margin on Sales":"519.059999999999","Cost-of-Goods Sold":"-8241","Average Price":"34.5723125","Last Price":"34.95","Cumulative COGS":"-62169.12","Cumulative Gross Margin":"126.35","GM Percentage":"0.0592530188149396","Cumulative GM Percentage":"0.00202823736621619"},{"trn":"87131116","sym":"GHI","tDate":"2013-11-16","qty":"-320.00","price_unit":"34.16","price_extended":"-10931.20","Inventory-On-Hand":"160","Inventory Cost":"5633.6","Gross Margin on Sales":"-29.909999999998","Cost-of-Goods Sold":"-10961.11","Average Price":"35.21","Last Price":"34.95","Cumulative COGS":"-73130.23","Cumulative Gross Margin":"96.4400000000019","GM Percentage":"-0.00273620462529256","Cumulative GM Percentage":"0.00131700649503797"},{"trn":"94131117","sym":"GHI","tDate":"2013-11-17","qty":"-92.00","price_unit":"32.65","price_extended":"-3003.80","Inventory-On-Hand":"68","Inventory Cost":"2394.28","Gross Margin on Sales":"-235.52","Cost-of-Goods Sold":"-3239.32","Average Price":"35.21","Last Price":"34.95","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"-0.0784073506891272","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"81131123","sym":"GHI","tDate":"2013-11-23","qty":"187.00","price_unit":"33.86","price_extended":"6331.82","Inventory-On-Hand":"255","Inventory Cost":"8726.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.22","Last Price":"33.86","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"51131206","sym":"GHI","tDate":"2013-12-06","qty":"85.00","price_unit":"33.64","price_extended":"2859.40","Inventory-On-Hand":"340","Inventory Cost":"11585.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.075","Last Price":"33.64","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"75131216","sym":"GHI","tDate":"2013-12-16","qty":"500.00","price_unit":"33.55","price_extended":"16775.00","Inventory-On-Hand":"840","Inventory Cost":"28360.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7625","Last Price":"33.55","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"13131221","sym":"GHI","tDate":"2013-12-21","qty":"72.00","price_unit":"34.38","price_extended":"2475.36","Inventory-On-Hand":"912","Inventory Cost":"30835.86","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.81125","Last Price":"34.38","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"65131227","sym":"GHI","tDate":"2013-12-27","qty":"376.00","price_unit":"33.49","price_extended":"12592.24","Inventory-On-Hand":"1288","Inventory Cost":"43428.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7174689440994","Last Price":"33.49","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"53140102","sym":"GHI","tDate":"2014-01-02","qty":"396.00","price_unit":"35.52","price_extended":"14065.92","Inventory-On-Hand":"1684","Inventory Cost":"57494.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1413420427553","Last Price":"35.52","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"18140125","sym":"GHI","tDate":"2014-01-25","qty":"-78.00","price_unit":"35.46","price_extended":"-2765.88","Inventory-On-Hand":"1606","Inventory Cost":"54723.46","Gross Margin on Sales":"-4.67999999999756","Cost-of-Goods Sold":"-2770.56","Average Price":"34.0743835616438","Last Price":"35.52","Cumulative COGS":"-79140.11","Cumulative Gross Margin":"-143.759999999996","GM Percentage":"-0.00169204737732568","Cumulative GM Percentage":"-0.00181983091623849"},{"trn":"37130220","sym":"XYZ","tDate":"2013-02-20","qty":"528.00","price_unit":"23.54","price_extended":"12429.12","Inventory-On-Hand":"528","Inventory Cost":"12429.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.54","Last Price":"23.54","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"44130227","sym":"XYZ","tDate":"2013-02-27","qty":"357.00","price_unit":"22.86","price_extended":"8161.02","Inventory-On-Hand":"885","Inventory Cost":"20590.14","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.2656949152542","Last Price":"22.86","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"67130302","sym":"XYZ","tDate":"2013-03-02","qty":"9.00","price_unit":"24.04","price_extended":"216.36","Inventory-On-Hand":"894","Inventory Cost":"20806.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.2734899328859","Last Price":"24.04","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"38130311","sym":"XYZ","tDate":"2013-03-11","qty":"-193.00","price_unit":"24.90","price_extended":"-4805.70","Inventory-On-Hand":"701","Inventory Cost":"16383.9","Gross Margin on Sales":"383.100000000001","Cost-of-Goods Sold":"-4422.6","Average Price":"23.372182596291","Last Price":"24.04","Cumulative COGS":"-4422.6","Cumulative Gross Margin":"383.100000000001","GM Percentage":"0.0797178350708536","Cumulative GM Percentage":"0.0797178350708536"},{"trn":"59130320","sym":"XYZ","tDate":"2013-03-20","qty":"-20.00","price_unit":"23.59","price_extended":"-471.80","Inventory-On-Hand":"681","Inventory Cost":"15926.7","Gross Margin on Sales":"14.5999999999993","Cost-of-Goods Sold":"-457.200000000001","Average Price":"23.3872246696035","Last Price":"24.04","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"0.0309453158117831","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"35130321","sym":"XYZ","tDate":"2013-03-21","qty":"275.00","price_unit":"24.83","price_extended":"6828.25","Inventory-On-Hand":"956","Inventory Cost":"22754.95","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8022489539749","Last Price":"24.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"98130413","sym":"XYZ","tDate":"2013-04-13","qty":"243.00","price_unit":"24.25","price_extended":"5892.75","Inventory-On-Hand":"1199","Inventory Cost":"28647.7","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8929941618015","Last Price":"24.25","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"24130418","sym":"XYZ","tDate":"2013-04-18","qty":"275.00","price_unit":"24.83","price_extended":"6828.25","Inventory-On-Hand":"1474","Inventory Cost":"35475.95","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0678086838535","Last Price":"24.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"60130419","sym":"XYZ","tDate":"2013-04-19","qty":"277.00","price_unit":"22.83","price_extended":"6323.91","Inventory-On-Hand":"1751","Inventory Cost":"41799.86","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8719931467733","Last Price":"22.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"83130428","sym":"XYZ","tDate":"2013-04-28","qty":"142.00","price_unit":"23.13","price_extended":"3284.46","Inventory-On-Hand":"1893","Inventory Cost":"45084.32","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8163338615954","Last Price":"23.13","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"34130507","sym":"XYZ","tDate":"2013-05-07","qty":"55.00","price_unit":"23.43","price_extended":"1288.65","Inventory-On-Hand":"1948","Inventory Cost":"46372.97","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8054260780287","Last Price":"23.43","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"99130515","sym":"XYZ","tDate":"2013-05-15","qty":"97.00","price_unit":"25.13","price_extended":"2437.61","Inventory-On-Hand":"2045","Inventory Cost":"48810.58","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8682542787286","Last Price":"25.13","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"19130516","sym":"XYZ","tDate":"2013-05-16","qty":"315.00","price_unit":"23.57","price_extended":"7424.55","Inventory-On-Hand":"2360","Inventory Cost":"56235.13","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8284449152542","Last Price":"23.57","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"30130519","sym":"XYZ","tDate":"2013-05-19","qty":"467.00","price_unit":"23.15","price_extended":"10811.05","Inventory-On-Hand":"2827","Inventory Cost":"67046.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7163707110011","Last Price":"23.15","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"29130602","sym":"XYZ","tDate":"2013-06-02","qty":"114.00","price_unit":"24.29","price_extended":"2769.06","Inventory-On-Hand":"2941","Inventory Cost":"69815.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.738605916355","Last Price":"24.29","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"91130615","sym":"XYZ","tDate":"2013-06-15","qty":"545.00","price_unit":"23.88","price_extended":"13014.60","Inventory-On-Hand":"3486","Inventory Cost":"82829.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.760711417097","Last Price":"23.88","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"23130619","sym":"XYZ","tDate":"2013-06-19","qty":"296.00","price_unit":"23.46","price_extended":"6944.16","Inventory-On-Hand":"3782","Inventory Cost":"89774","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.737176097303","Last Price":"23.46","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"47130619","sym":"XYZ","tDate":"2013-06-19","qty":"413.00","price_unit":"25.18","price_extended":"10399.34","Inventory-On-Hand":"4195","Inventory Cost":"100173.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8792228843862","Last Price":"25.18","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"74130619","sym":"XYZ","tDate":"2013-06-19","qty":"202.00","price_unit":"22.95","price_extended":"4635.90","Inventory-On-Hand":"4397","Inventory Cost":"104809.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8365340004549","Last Price":"22.95","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"55130630","sym":"XYZ","tDate":"2013-06-30","qty":"-272.00","price_unit":"23.45","price_extended":"-6378.40","Inventory-On-Hand":"4125","Inventory Cost":"98410.74","Gross Margin on Sales":"-20.0999999999858","Cost-of-Goods Sold":"-6398.49999999999","Average Price":"23.8571490909091","Last Price":"22.95","Cumulative COGS":"-11278.3","Cumulative Gross Margin":"377.600000000015","GM Percentage":"-0.00315126050419946","Cumulative GM Percentage":"0.0323956108065456"},{"trn":"14130705","sym":"XYZ","tDate":"2013-07-05","qty":"-277.00","price_unit":"25.01","price_extended":"-6927.77","Inventory-On-Hand":"3848","Inventory Cost":"91435.88","Gross Margin on Sales":"-47.0900000000001","Cost-of-Goods Sold":"-6974.86","Average Price":"23.7619230769231","Last Price":"22.95","Cumulative COGS":"-18253.16","Cumulative Gross Margin":"330.510000000015","GM Percentage":"-0.00679728108756499","Cumulative GM Percentage":"0.0177849692767906"},{"trn":"5130706","sym":"XYZ","tDate":"2013-07-06","qty":"-170.00","price_unit":"23.46","price_extended":"-3988.20","Inventory-On-Hand":"3678","Inventory Cost":"87334.16","Gross Margin on Sales":"-113.520000000016","Cost-of-Goods Sold":"-4101.72000000002","Average Price":"23.7450135943448","Last Price":"22.95","Cumulative COGS":"-22354.88","Cumulative Gross Margin":"216.989999999999","GM Percentage":"-0.0284639687076917","Cumulative GM Percentage":"0.00961329300585192"},{"trn":"58130722","sym":"XYZ","tDate":"2013-07-22","qty":"-88.00","price_unit":"24.64","price_extended":"-2168.32","Inventory-On-Hand":"3590","Inventory Cost":"85269.68","Gross Margin on Sales":"103.840000000004","Cost-of-Goods Sold":"-2064.48","Average Price":"23.752","Last Price":"22.95","Cumulative COGS":"-24419.36","Cumulative Gross Margin":"320.830000000003","GM Percentage":"0.0478896103896123","Cumulative GM Percentage":"0.0129679683139056"},{"trn":"57130813","sym":"XYZ","tDate":"2013-08-13","qty":"-163.00","price_unit":"23.65","price_extended":"-3854.95","Inventory-On-Hand":"3427","Inventory Cost":"81420.92","Gross Margin on Sales":"6.19000000000506","Cost-of-Goods Sold":"-3848.75999999999","Average Price":"23.7586577181208","Last Price":"22.95","Cumulative COGS":"-28268.12","Cumulative Gross Margin":"327.020000000008","GM Percentage":"0.0016057277007497","Cumulative GM Percentage":"0.0114362090900764"},{"trn":"54130831","sym":"XYZ","tDate":"2013-08-31","qty":"-61.00","price_unit":"23.23","price_extended":"-1417.03","Inventory-On-Hand":"3366","Inventory Cost":"79964.24","Gross Margin on Sales":"-39.6500000000076","Cost-of-Goods Sold":"-1456.68000000001","Average Price":"23.756458704694","Last Price":"22.95","Cumulative COGS":"-29724.8","Cumulative Gross Margin":"287.37","GM Percentage":"-0.0279810589754681","Cumulative GM Percentage":"0.00957511569473318"},{"trn":"11130906","sym":"XYZ","tDate":"2013-09-06","qty":"-13.00","price_unit":"23.97","price_extended":"-311.61","Inventory-On-Hand":"3353","Inventory Cost":"79653.8","Gross Margin on Sales":"1.16999999999769","Cost-of-Goods Sold":"-310.440000000002","Average Price":"23.755979719654","Last Price":"22.95","Cumulative COGS":"-30035.24","Cumulative Gross Margin":"288.539999999998","GM Percentage":"0.00375469336670096","Cumulative GM Percentage":"0.00951530449040318"},{"trn":"27130906","sym":"XYZ","tDate":"2013-09-06","qty":"-147.00","price_unit":"23.81","price_extended":"-3500.07","Inventory-On-Hand":"3206","Inventory Cost":"76143.44","Gross Margin on Sales":"-10.2900000000004","Cost-of-Goods Sold":"-3510.36","Average Price":"23.7502932002495","Last Price":"22.95","Cumulative COGS":"-33545.6","Cumulative Gross Margin":"278.249999999998","GM Percentage":"-0.0029399412011761","Cumulative GM Percentage":"0.00822644376675031"},{"trn":"36130917","sym":"XYZ","tDate":"2013-09-17","qty":"92.00","price_unit":"24.60","price_extended":"2263.20","Inventory-On-Hand":"3298","Inventory Cost":"78406.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7739963614312","Last Price":"24.6","Cumulative COGS":"-33545.6","Cumulative Gross Margin":"278.249999999998","GM Percentage":"NULL","Cumulative GM Percentage":"0.00822644376675031"},{"trn":"92130924","sym":"XYZ","tDate":"2013-09-24","qty":"-248.00","price_unit":"24.58","price_extended":"-6095.84","Inventory-On-Hand":"3050","Inventory Cost":"72418.16","Gross Margin on Sales":"107.360000000004","Cost-of-Goods Sold":"-5988.48","Average Price":"23.7436590163934","Last Price":"24.6","Cumulative COGS":"-39534.08","Cumulative Gross Margin":"385.610000000002","GM Percentage":"0.0176120108139328","Cumulative GM Percentage":"0.0096596441505433"},{"trn":"42131011","sym":"XYZ","tDate":"2013-10-11","qty":"-250.00","price_unit":"23.12","price_extended":"-5780.00","Inventory-On-Hand":"2800","Inventory Cost":"66421.13","Gross Margin on Sales":"-217.029999999999","Cost-of-Goods Sold":"-5997.03","Average Price":"23.7218321428571","Last Price":"24.6","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"-0.0375484429065742","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"22131012","sym":"XYZ","tDate":"2013-10-12","qty":"596.00","price_unit":"23.16","price_extended":"13803.36","Inventory-On-Hand":"3396","Inventory Cost":"80224.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.623230270907","Last Price":"23.16","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"40131013","sym":"XYZ","tDate":"2013-10-13","qty":"359.00","price_unit":"23.91","price_extended":"8583.69","Inventory-On-Hand":"3755","Inventory Cost":"88808.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6506471371505","Last Price":"23.91","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"1131019","sym":"XYZ","tDate":"2013-10-19","qty":"424.00","price_unit":"25.13","price_extended":"10655.12","Inventory-On-Hand":"4179","Inventory Cost":"99463.3","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8007418042594","Last Price":"25.13","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"9131025","sym":"XYZ","tDate":"2013-10-25","qty":"-153.00","price_unit":"24.31","price_extended":"-3719.43","Inventory-On-Hand":"4026","Inventory Cost":"95618.41","Gross Margin on Sales":"-125.46","Cost-of-Goods Sold":"-3844.89","Average Price":"23.7502260307998","Last Price":"25.13","Cumulative COGS":"-49376","Cumulative Gross Margin":"43.1200000000035","GM Percentage":"-0.0337309749074454","Cumulative GM Percentage":"0.000872536783334132"},{"trn":"62131027","sym":"XYZ","tDate":"2013-10-27","qty":"-248.00","price_unit":"24.71","price_extended":"-6128.08","Inventory-On-Hand":"3778","Inventory Cost":"89386.17","Gross Margin on Sales":"-104.159999999991","Cost-of-Goods Sold":"-6232.23999999999","Average Price":"23.6596532556908","Last Price":"25.13","Cumulative COGS":"-55608.24","Cumulative Gross Margin":"-61.0399999999873","GM Percentage":"-0.0169971671388087","Cumulative GM Percentage":"-0.00109888527234473"},{"trn":"45131030","sym":"XYZ","tDate":"2013-10-30","qty":"-350.00","price_unit":"23.36","price_extended":"-8176.00","Inventory-On-Hand":"3428","Inventory Cost":"80989.61","Gross Margin on Sales":"-220.560000000012","Cost-of-Goods Sold":"-8396.56000000001","Average Price":"23.6259072345391","Last Price":"25.13","Cumulative COGS":"-64004.8","Cumulative Gross Margin":"-281.6","GM Percentage":"-0.0269765166340524","Cumulative GM Percentage":"-0.00441911266226429"},{"trn":"21131103","sym":"XYZ","tDate":"2013-11-03","qty":"-326.00","price_unit":"23.24","price_extended":"-7576.24","Inventory-On-Hand":"3102","Inventory Cost":"73415.45","Gross Margin on Sales":"2.08000000001084","Cost-of-Goods Sold":"-7574.15999999999","Average Price":"23.6671341070277","Last Price":"25.13","Cumulative COGS":"-71578.96","Cumulative Gross Margin":"-279.519999999989","GM Percentage":"0.00027454251713394","Cumulative GM Percentage":"-0.00392036739699482"},{"trn":"97131125","sym":"XYZ","tDate":"2013-11-25","qty":"-278.00","price_unit":"23.18","price_extended":"-6444.04","Inventory-On-Hand":"2824","Inventory Cost":"66976.97","Gross Margin on Sales":"5.55999999998949","Cost-of-Goods Sold":"-6438.48000000001","Average Price":"23.7170573654391","Last Price":"25.13","Cumulative COGS":"-78017.44","Cumulative Gross Margin":"-273.959999999999","GM Percentage":"0.000862812769627359","Cumulative GM Percentage":"-0.00352389679494665"},{"trn":"28131209","sym":"XYZ","tDate":"2013-12-09","qty":"315.00","price_unit":"24.46","price_extended":"7704.90","Inventory-On-Hand":"3139","Inventory Cost":"74681.87","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.791611978337","Last Price":"24.46","Cumulative COGS":"-78017.44","Cumulative Gross Margin":"-273.959999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00352389679494665"},{"trn":"79131223","sym":"XYZ","tDate":"2013-12-23","qty":"-376.00","price_unit":"25.12","price_extended":"-9445.12","Inventory-On-Hand":"2763","Inventory Cost":"65564.58","Gross Margin on Sales":"327.830000000007","Cost-of-Goods Sold":"-9117.28999999999","Average Price":"23.7294896851249","Last Price":"24.46","Cumulative COGS":"-87134.73","Cumulative Gross Margin":"53.870000000008","GM Percentage":"0.0347089290554283","Cumulative GM Percentage":"0.000617856004110721"},{"trn":"33140102","sym":"XYZ","tDate":"2014-01-02","qty":"-196.00","price_unit":"22.98","price_extended":"-4504.08","Inventory-On-Hand":"2567","Inventory Cost":"61027.18","Gross Margin on Sales":"-33.3199999999943","Cost-of-Goods Sold":"-4537.39999999999","Average Price":"23.7737358784573","Last Price":"24.46","Cumulative COGS":"-91672.13","Cumulative Gross Margin":"20.5500000000138","GM Percentage":"-0.00739773716274894","Cumulative GM Percentage":"0.000224118217506717"},{"trn":"84140104","sym":"XYZ","tDate":"2014-01-04","qty":"261.00","price_unit":"24.46","price_extended":"6384.06","Inventory-On-Hand":"2828","Inventory Cost":"67411.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.837072135785","Last Price":"24.46","Cumulative COGS":"-91672.13","Cumulative Gross Margin":"20.5500000000138","GM Percentage":"NULL","Cumulative GM Percentage":"0.000224118217506717"},{"trn":"64140109","sym":"XYZ","tDate":"2014-01-09","qty":"-253.00","price_unit":"24.46","price_extended":"-6188.38","Inventory-On-Hand":"2575","Inventory Cost":"61222.86","Gross Margin on Sales":"2.72848410531878E-12","Cost-of-Goods Sold":"-6188.38","Average Price":"23.7758679611651","Last Price":"24.46","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"4.40904421725683E-16","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"78140112","sym":"XYZ","tDate":"2014-01-12","qty":"332.00","price_unit":"24.28","price_extended":"8060.96","Inventory-On-Hand":"2907","Inventory Cost":"69283.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8334434124527","Last Price":"24.28","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"80140126","sym":"XYZ","tDate":"2014-01-26","qty":"404.00","price_unit":"24.23","price_extended":"9788.92","Inventory-On-Hand":"3311","Inventory Cost":"79072.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8818302627605","Last Price":"24.23","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"82140131","sym":"XYZ","tDate":"2014-01-31","qty":"548.00","price_unit":"23.65","price_extended":"12960.20","Inventory-On-Hand":"3859","Inventory Cost":"92032.94","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8489090437937","Last Price":"23.65","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"66140203","sym":"XYZ","tDate":"2014-02-03","qty":"459.00","price_unit":"23.70","price_extended":"10878.30","Inventory-On-Hand":"4318","Inventory Cost":"102911.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8330801296897","Last Price":"23.7","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"72140204","sym":"XYZ","tDate":"2014-02-04","qty":"-208.00","price_unit":"24.36","price_extended":"-5066.88","Inventory-On-Hand":"4110","Inventory Cost":"97981.64","Gross Margin on Sales":"137.279999999994","Cost-of-Goods Sold":"-4929.60000000001","Average Price":"23.8398150851582","Last Price":"23.7","Cumulative COGS":"-102790.11","Cumulative Gross Margin":"157.830000000011","GM Percentage":"0.0270935960591122","Cumulative GM Percentage":"0.00153310498490801"},{"trn":"31140205","sym":"XYZ","tDate":"2014-02-05","qty":"42.00","price_unit":"24.39","price_extended":"1024.38","Inventory-On-Hand":"4152","Inventory Cost":"99006.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.845380539499","Last Price":"24.39","Cumulative COGS":"-102790.11","Cumulative Gross Margin":"157.830000000011","GM Percentage":"NULL","Cumulative GM Percentage":"0.00153310498490801"}]}
Example #2 In this example, we will look at a simple FX blotter. In FX trading, it is not at all unusual to switch from a long currency position to a short currency position during the course of a day. Additionally, if you are trading something like the US dollars against the Euro, if you are long US dollars, you are short the Euro. Thus, it’s critical to pay attention to the sign. We will create the #fx table and populate it with some data.
--Create the temporary table
CREATE TABLE #fx (
trn int,
ccy char(3),
amt_ccy money,
rate float,
ctr char(3),
amt_ctr money,
PRIMARY KEY (trn));
--Populate the table with some data
INSERT INTO #fx
VALUES (101, 'GBP', 8000000, 1.619, 'USD', -12952000);
INSERT INTO #fx
VALUES (102, 'GBP', -10000000, 1.62, 'USD', 16200000);
INSERT INTO #fx
VALUES (103, 'GBP', -4000000, 1.613, 'USD', 6452000);
INSERT INTO #fx
VALUES (104, 'GBP', 7000000, 1.618, 'USD', -11326000);
INSERT INTO #fx
VALUES (105, 'GBP', 6000000, 1.623, 'USD', -9738000);
INSERT INTO #fx
VALUES (106, 'GBP', -5000000, 1.618, 'USD', 8090000);
INSERT INTO #fx
VALUES (107, 'GBP', -10000000, 1.602, 'USD', 16020000);
INSERT INTO #fx
VALUES (108, 'GBP', 2000000, 1.608, 'USD', -3216000);
INSERT INTO #fx
VALUES (109, 'GBP', -2000000, 1.602, 'USD', 3204000);
INSERT INTO #fx
VALUES (110, 'GBP', 10000000, 1.626, 'USD', -16260000);
--Calculate the LIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #lifo
FROM wct.LIFOtvf('SELECT trn, ROW_NUMBER() OVER (ORDER BY trn),amt_ccy,-amt_ctr FROM #fx ORDER BY trn');
--JOIN to the source data to produce the inventory output
SELECT c.trn,
c.ccy,
c.amt_ccy,
c.rate,
c.ctr,
c.amt_ctr,
l.[QTY] as [GBP Position],
l.[EB] as [USD Position],
l.[GM] as [P/L],
l.[COGS] as [Cost-of-Goods Sold],
l.[UP] as [Average Price],
l.[LP] as [Last Price],
l.[COGSC] as [Cumulative COGS],
l.[GMC] as [Cumulative P/L],
l.[GMP] as [GM Percentage],
l.[CGMP] as [Cumulative GM Percentage]
FROM #fx c
INNER JOIN #LIFO l
ON c.trn = l.[ID]
ORDER BY c.trn;
This produces the following result.
{"columns":[{"field":"trn","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ccy"},{"field":"amt_ccy","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"rate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ctr"},{"field":"amt_ctr","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GBP Position","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"USD Position","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"P/L","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cost-of-Goods Sold","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Average Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Last Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative COGS","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative P/L","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GM Percentage"},{"field":"Cumulative GM Percentage"}],"rows":[{"trn":"101","ccy":"GBP","amt_ccy":"8000000.00","rate":"1.619","ctr":"USD","amt_ctr":"-12952000.00","GBP Position":"8000000","USD Position":"12952000","P/L":"0","Cost-of-Goods Sold":"0","Average Price":"1.619","Last Price":"1.619","Cumulative COGS":"0","Cumulative P/L":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"102","ccy":"GBP","amt_ccy":"-10000000.00","rate":"1.62","ctr":"USD","amt_ctr":"16200000.00","GBP Position":"-2000000","USD Position":"-3240000","P/L":"8000","Cost-of-Goods Sold":"-12952000","Average Price":"1.62","Last Price":"1.62","Cumulative COGS":"-12952000","Cumulative P/L":"8000","GM Percentage":"0.000617283950617284","Cumulative GM Percentage":"0.000617283950617284"},{"trn":"103","ccy":"GBP","amt_ccy":"-4000000.00","rate":"1.613","ctr":"USD","amt_ctr":"6452000.00","GBP Position":"-6000000","USD Position":"-9692000","P/L":"0","Cost-of-Goods Sold":"0","Average Price":"1.61533333333333","Last Price":"1.613","Cumulative COGS":"-12952000","Cumulative P/L":"8000","GM Percentage":"NULL","Cumulative GM Percentage":"0.000617283950617284"},{"trn":"104","ccy":"GBP","amt_ccy":"7000000.00","rate":"1.618","ctr":"USD","amt_ctr":"-11326000.00","GBP Position":"1000000","USD Position":"1618000","P/L":"-16000","Cost-of-Goods Sold":"9692000","Average Price":"1.618","Last Price":"1.618","Cumulative COGS":"-3260000","Cumulative P/L":"-8000","GM Percentage":"0.00164812525751957","Cumulative GM Percentage":"-0.002460024600246"},{"trn":"105","ccy":"GBP","amt_ccy":"6000000.00","rate":"1.623","ctr":"USD","amt_ctr":"-9738000.00","GBP Position":"7000000","USD Position":"11356000","P/L":"0","Cost-of-Goods Sold":"0","Average Price":"1.62228571428571","Last Price":"1.623","Cumulative COGS":"-3260000","Cumulative P/L":"-8000","GM Percentage":"NULL","Cumulative GM Percentage":"-0.002460024600246"},{"trn":"106","ccy":"GBP","amt_ccy":"-5000000.00","rate":"1.618","ctr":"USD","amt_ctr":"8090000.00","GBP Position":"2000000","USD Position":"3241000","P/L":"-25000","Cost-of-Goods Sold":"-8115000","Average Price":"1.6205","Last Price":"1.623","Cumulative COGS":"-11375000","Cumulative P/L":"-33000","GM Percentage":"-0.0030902348578492","Cumulative GM Percentage":"-0.0029095397637101"},{"trn":"107","ccy":"GBP","amt_ccy":"-10000000.00","rate":"1.602","ctr":"USD","amt_ctr":"16020000.00","GBP Position":"-8000000","USD Position":"-12816000","P/L":"-37000","Cost-of-Goods Sold":"-3241000","Average Price":"1.602","Last Price":"1.602","Cumulative COGS":"-14616000","Cumulative P/L":"-70000","GM Percentage":"-0.0115480649188514","Cumulative GM Percentage":"-0.00481231953801732"},{"trn":"108","ccy":"GBP","amt_ccy":"2000000.00","rate":"1.608","ctr":"USD","amt_ctr":"-3216000.00","GBP Position":"-6000000","USD Position":"-9612000","P/L":"-12000","Cost-of-Goods Sold":"3204000","Average Price":"1.602","Last Price":"1.602","Cumulative COGS":"-11412000","Cumulative P/L":"-82000","GM Percentage":"0.00373134328358209","Cumulative GM Percentage":"-0.00723742277140335"},{"trn":"109","ccy":"GBP","amt_ccy":"-2000000.00","rate":"1.602","ctr":"USD","amt_ctr":"3204000.00","GBP Position":"-8000000","USD Position":"-12816000","P/L":"0","Cost-of-Goods Sold":"0","Average Price":"1.602","Last Price":"1.602","Cumulative COGS":"-11412000","Cumulative P/L":"-82000","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00723742277140335"},{"trn":"110","ccy":"GBP","amt_ccy":"10000000.00","rate":"1.626","ctr":"USD","amt_ctr":"-16260000.00","GBP Position":"2000000","USD Position":"3252000","P/L":"-192000","Cost-of-Goods Sold":"12816000","Average Price":"1.626","Last Price":"1.626","Cumulative COGS":"1404000","Cumulative P/L":"-274000","GM Percentage":"0.014760147601476","Cumulative GM Percentage":"0.163289630512515"}]}
Example #3 Using the #c temp table created in Example #1, we will insert the necessary input for the LIFOtvf into the #inv temp table containing an IDENTITY column which is then used to link the input data to the output data. This simplifies the @DataQuery SQL.
--put the #c data into #inv
SELECT IDENTITY(int, 1, 1) as id,
trn,
ROW_NUMBER() OVER (PARTITION by sym ORDER BY sym, tDate, trn) as rn,
qty,
price_extended
INTO #inv
FROM #c
ORDER BY sym,
tDate,
trn;
--Calculate the LIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #LIFO
FROM wct.LIFOtvf('SELECT id,rn,qty,price_extended FROM #inv ORDER BY id');
--JOIN to the source data to produce the inventory output
SELECT i.trn,
c.sym,
c.tDate,
i.qty,
c.price_unit,
i.price_extended,
l.[QTY] as [Inventory-On-Hand],
l.[EB] as [Inventory Cost],
l.[GM] as [Gross Margin on Sales],
l.[COGS] as [Cost-of-Goods Sold],
l.[UP] as [Average Price],
l.[LP] as [Last Price],
l.[COGSC] as [Cumulative COGS],
l.[GMC] as [Cumulative Gross Margin],
l.[GMP] as [GM Percentage],
l.[CGMP] as [Cumulative GM Percentage]
FROM #inv i
INNER JOIN #LIFO l
ON i.ID = l.[ID]
INNER JOIN #c c
ON i.trn = c.trn
ORDER BY i.id;
This produces the following result.
{"columns":[{"field":"trn","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"sym"},{"field":"tDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"qty","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"price_unit","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"price_extended","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory-On-Hand","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory Cost","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Gross Margin on Sales","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cost-of-Goods Sold","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Average Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Last Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative COGS","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative Gross Margin","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GM Percentage"},{"field":"Cumulative GM Percentage"}],"rows":[{"trn":"68130223","sym":"ABC","tDate":"2013-02-23","qty":"238.00","price_unit":"12.78","price_extended":"3041.64","Inventory-On-Hand":"238","Inventory Cost":"3041.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"12.78","Last Price":"12.78","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"46130301","sym":"ABC","tDate":"2013-03-01","qty":"157.00","price_unit":"13.01","price_extended":"2042.57","Inventory-On-Hand":"395","Inventory Cost":"5084.21","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"12.871417721519","Last Price":"13.01","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"3130308","sym":"ABC","tDate":"2013-03-08","qty":"-157.00","price_unit":"13.17","price_extended":"-2067.69","Inventory-On-Hand":"238","Inventory Cost":"3041.64","Gross Margin on Sales":"25.1199999999999","Cost-of-Goods Sold":"-2042.57","Average Price":"12.78","Last Price":"13.01","Cumulative COGS":"-2042.57","Cumulative Gross Margin":"25.1199999999999","GM Percentage":"0.0121488230827638","Cumulative GM Percentage":"0.0121488230827638"},{"trn":"32130310","sym":"ABC","tDate":"2013-03-10","qty":"-63.00","price_unit":"12.61","price_extended":"-794.43","Inventory-On-Hand":"175","Inventory Cost":"2236.5","Gross Margin on Sales":"-10.7099999999999","Cost-of-Goods Sold":"-805.14","Average Price":"12.78","Last Price":"13.01","Cumulative COGS":"-2847.71","Cumulative Gross Margin":"14.41","GM Percentage":"-0.0134813639968278","Cumulative GM Percentage":"0.00503472950120888"},{"trn":"41130310","sym":"ABC","tDate":"2013-03-10","qty":"463.00","price_unit":"13.38","price_extended":"6194.94","Inventory-On-Hand":"638","Inventory Cost":"8431.44","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2154231974922","Last Price":"13.38","Cumulative COGS":"-2847.71","Cumulative Gross Margin":"14.41","GM Percentage":"NULL","Cumulative GM Percentage":"0.00503472950120888"},{"trn":"26130320","sym":"ABC","tDate":"2013-03-20","qty":"-92.00","price_unit":"13.64","price_extended":"-1254.88","Inventory-On-Hand":"546","Inventory Cost":"7200.48","Gross Margin on Sales":"23.920000000001","Cost-of-Goods Sold":"-1230.96","Average Price":"13.1876923076923","Last Price":"13.38","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"0.0190615835777134","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"25130408","sym":"ABC","tDate":"2013-04-08","qty":"298.00","price_unit":"12.98","price_extended":"3868.04","Inventory-On-Hand":"844","Inventory Cost":"11068.52","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1143601895735","Last Price":"12.98","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"48130430","sym":"ABC","tDate":"2013-04-30","qty":"229.00","price_unit":"13.32","price_extended":"3050.28","Inventory-On-Hand":"1073","Inventory Cost":"14118.8","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1582479030755","Last Price":"13.32","Cumulative COGS":"-4078.67","Cumulative Gross Margin":"38.330000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00931017731357808"},{"trn":"90130430","sym":"ABC","tDate":"2013-04-30","qty":"-191.00","price_unit":"13.49","price_extended":"-2576.59","Inventory-On-Hand":"882","Inventory Cost":"11574.68","Gross Margin on Sales":"32.4699999999993","Cost-of-Goods Sold":"-2544.12","Average Price":"13.1232199546485","Last Price":"13.32","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"0.012601927353595","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"49130508","sym":"ABC","tDate":"2013-05-08","qty":"238.00","price_unit":"12.79","price_extended":"3044.02","Inventory-On-Hand":"1120","Inventory Cost":"14618.7","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0524107142857","Last Price":"12.79","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"20130518","sym":"ABC","tDate":"2013-05-18","qty":"298.00","price_unit":"13.23","price_extended":"3942.54","Inventory-On-Hand":"1418","Inventory Cost":"18561.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0897320169252","Last Price":"13.23","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"89130611","sym":"ABC","tDate":"2013-06-11","qty":"130.00","price_unit":"13.02","price_extended":"1692.60","Inventory-On-Hand":"1548","Inventory Cost":"20253.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0838759689922","Last Price":"13.02","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"2130617","sym":"ABC","tDate":"2013-06-17","qty":"313.00","price_unit":"12.93","price_extended":"4047.09","Inventory-On-Hand":"1861","Inventory Cost":"24300.93","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0579957012359","Last Price":"12.93","Cumulative COGS":"-6622.79","Cumulative Gross Margin":"70.8000000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105772836400198"},{"trn":"12130621","sym":"ABC","tDate":"2013-06-21","qty":"-326.00","price_unit":"12.73","price_extended":"-4149.98","Inventory-On-Hand":"1535","Inventory Cost":"20084.58","Gross Margin on Sales":"-66.369999999999","Cost-of-Goods Sold":"-4216.35","Average Price":"13.0844169381108","Last Price":"12.93","Cumulative COGS":"-10839.14","Cumulative Gross Margin":"4.43000000000131","GM Percentage":"-0.0159928481583041","Cumulative GM Percentage":"0.000408537040845525"},{"trn":"93130622","sym":"ABC","tDate":"2013-06-22","qty":"-227.00","price_unit":"13.47","price_extended":"-3057.69","Inventory-On-Hand":"1308","Inventory Cost":"17105.94","Gross Margin on Sales":"79.0500000000006","Cost-of-Goods Sold":"-2978.64","Average Price":"13.0779357798165","Last Price":"12.93","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"0.0258528497002641","Cumulative GM Percentage":"0.006005211038424"},{"trn":"7130722","sym":"ABC","tDate":"2013-07-22","qty":"599.00","price_unit":"13.65","price_extended":"8176.35","Inventory-On-Hand":"1907","Inventory Cost":"25282.29","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2576245411641","Last Price":"13.65","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"NULL","Cumulative GM Percentage":"0.006005211038424"},{"trn":"71130731","sym":"ABC","tDate":"2013-07-31","qty":"79.00","price_unit":"13.55","price_extended":"1070.45","Inventory-On-Hand":"1986","Inventory Cost":"26352.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2692547834844","Last Price":"13.55","Cumulative COGS":"-13817.78","Cumulative Gross Margin":"83.480000000002","GM Percentage":"NULL","Cumulative GM Percentage":"0.006005211038424"},{"trn":"10130908","sym":"ABC","tDate":"2013-09-08","qty":"-386.00","price_unit":"13.65","price_extended":"-5268.90","Inventory-On-Hand":"1600","Inventory Cost":"21091.74","Gross Margin on Sales":"7.89999999999964","Cost-of-Goods Sold":"-5261","Average Price":"13.1823375","Last Price":"13.55","Cumulative COGS":"-19078.78","Cumulative Gross Margin":"91.3800000000016","GM Percentage":"0.00149936419366464","Cumulative GM Percentage":"0.00476678337583002"},{"trn":"39130908","sym":"ABC","tDate":"2013-09-08","qty":"490.00","price_unit":"12.69","price_extended":"6218.10","Inventory-On-Hand":"2090","Inventory Cost":"27309.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.0669090909091","Last Price":"12.69","Cumulative COGS":"-19078.78","Cumulative Gross Margin":"91.3800000000016","GM Percentage":"NULL","Cumulative GM Percentage":"0.00476678337583002"},{"trn":"61130916","sym":"ABC","tDate":"2013-09-16","qty":"-202.00","price_unit":"12.94","price_extended":"-2613.88","Inventory-On-Hand":"1888","Inventory Cost":"24746.46","Gross Margin on Sales":"50.4999999999991","Cost-of-Goods Sold":"-2563.38","Average Price":"13.1072351694915","Last Price":"12.69","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"0.0193199381761975","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"76131009","sym":"ABC","tDate":"2013-10-09","qty":"249.00","price_unit":"13.47","price_extended":"3354.03","Inventory-On-Hand":"2137","Inventory Cost":"28100.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1495039775386","Last Price":"13.47","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"88131009","sym":"ABC","tDate":"2013-10-09","qty":"187.00","price_unit":"13.36","price_extended":"2498.32","Inventory-On-Hand":"2324","Inventory Cost":"30598.81","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1664414802065","Last Price":"13.36","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"16131107","sym":"ABC","tDate":"2013-11-07","qty":"27.00","price_unit":"12.68","price_extended":"342.36","Inventory-On-Hand":"2351","Inventory Cost":"30941.17","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1608549553382","Last Price":"12.68","Cumulative COGS":"-21642.16","Cumulative Gross Margin":"141.880000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.00651302513216101"},{"trn":"86131114","sym":"ABC","tDate":"2013-11-14","qty":"-386.00","price_unit":"12.40","price_extended":"-4786.40","Inventory-On-Hand":"1965","Inventory Cost":"25783.65","Gross Margin on Sales":"-371.120000000001","Cost-of-Goods Sold":"-5157.52","Average Price":"13.1214503816794","Last Price":"12.68","Cumulative COGS":"-26799.68","Cumulative Gross Margin":"-229.24","GM Percentage":"-0.0775363530001673","Cumulative GM Percentage":"-0.00862763281300574"},{"trn":"8131231","sym":"ABC","tDate":"2013-12-31","qty":"-145.00","price_unit":"13.19","price_extended":"-1912.55","Inventory-On-Hand":"1820","Inventory Cost":"23883.54","Gross Margin on Sales":"12.4399999999994","Cost-of-Goods Sold":"-1900.11","Average Price":"13.1228241758242","Last Price":"12.68","Cumulative COGS":"-28699.79","Cumulative Gross Margin":"-216.800000000001","GM Percentage":"0.00650440511359147","Cumulative GM Percentage":"-0.00761156044361918"},{"trn":"15130307","sym":"GHI","tDate":"2013-03-07","qty":"559.00","price_unit":"35.21","price_extended":"19682.39","Inventory-On-Hand":"559","Inventory Cost":"19682.39","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"35.21","Last Price":"35.21","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"69130403","sym":"GHI","tDate":"2013-04-03","qty":"-151.00","price_unit":"33.16","price_extended":"-5007.16","Inventory-On-Hand":"408","Inventory Cost":"14365.68","Gross Margin on Sales":"-309.549999999999","Cost-of-Goods Sold":"-5316.71","Average Price":"35.21","Last Price":"35.21","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"-0.0618214716525933","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"56130419","sym":"GHI","tDate":"2013-04-19","qty":"416.00","price_unit":"34.46","price_extended":"14335.36","Inventory-On-Hand":"824","Inventory Cost":"28701.04","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.831359223301","Last Price":"34.46","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"4130516","sym":"GHI","tDate":"2013-05-16","qty":"160.00","price_unit":"34.48","price_extended":"5516.80","Inventory-On-Hand":"984","Inventory Cost":"34217.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.7742276422764","Last Price":"34.48","Cumulative COGS":"-5316.71","Cumulative Gross Margin":"-309.549999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0618214716525933"},{"trn":"43130521","sym":"GHI","tDate":"2013-05-21","qty":"-174.00","price_unit":"34.20","price_extended":"-5950.80","Inventory-On-Hand":"810","Inventory Cost":"28218.6","Gross Margin on Sales":"-48.4400000000051","Cost-of-Goods Sold":"-5999.24000000001","Average Price":"34.8377777777778","Last Price":"34.48","Cumulative COGS":"-11315.95","Cumulative Gross Margin":"-357.990000000004","GM Percentage":"-0.00814008200578159","Cumulative GM Percentage":"-0.03266940196898"},{"trn":"70130702","sym":"GHI","tDate":"2013-07-02","qty":"-162.00","price_unit":"35.48","price_extended":"-5747.76","Inventory-On-Hand":"648","Inventory Cost":"22636.08","Gross Margin on Sales":"165.240000000003","Cost-of-Goods Sold":"-5582.52","Average Price":"34.9322222222222","Last Price":"34.48","Cumulative COGS":"-16898.47","Cumulative Gross Margin":"-192.750000000001","GM Percentage":"0.0287485907553557","Cumulative GM Percentage":"-0.0115379642421878"},{"trn":"96130716","sym":"GHI","tDate":"2013-07-16","qty":"-347.00","price_unit":"35.29","price_extended":"-12245.63","Inventory-On-Hand":"301","Inventory Cost":"10598.21","Gross Margin on Sales":"207.759999999998","Cost-of-Goods Sold":"-12037.87","Average Price":"35.21","Last Price":"34.48","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"0.0169660523795018","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"63130806","sym":"GHI","tDate":"2013-08-06","qty":"445.00","price_unit":"33.50","price_extended":"14907.50","Inventory-On-Hand":"746","Inventory Cost":"25505.71","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1899597855228","Last Price":"33.5","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"77130825","sym":"GHI","tDate":"2013-08-25","qty":"272.00","price_unit":"33.86","price_extended":"9209.92","Inventory-On-Hand":"1018","Inventory Cost":"34715.63","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1017976424361","Last Price":"33.86","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"95130908","sym":"GHI","tDate":"2013-09-08","qty":"103.00","price_unit":"35.42","price_extended":"3648.26","Inventory-On-Hand":"1121","Inventory Cost":"38363.89","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.2229170383586","Last Price":"35.42","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"6130924","sym":"GHI","tDate":"2013-09-24","qty":"328.00","price_unit":"34.95","price_extended":"11463.60","Inventory-On-Hand":"1449","Inventory Cost":"49827.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.3875017253278","Last Price":"34.95","Cumulative COGS":"-28936.34","Cumulative Gross Margin":"15.0099999999975","GM Percentage":"NULL","Cumulative GM Percentage":"0.000518455961466304"},{"trn":"17130924","sym":"GHI","tDate":"2013-09-24","qty":"-291.00","price_unit":"35.69","price_extended":"-10385.79","Inventory-On-Hand":"1158","Inventory Cost":"39657.04","Gross Margin on Sales":"215.340000000004","Cost-of-Goods Sold":"-10170.45","Average Price":"34.2461485319516","Last Price":"34.95","Cumulative COGS":"-39106.79","Cumulative Gross Margin":"230.350000000001","GM Percentage":"0.0207340991874478","Cumulative GM Percentage":"0.0058557892109086"},{"trn":"85131002","sym":"GHI","tDate":"2013-10-02","qty":"-295.00","price_unit":"32.51","price_extended":"-9590.45","Inventory-On-Hand":"863","Inventory Cost":"29467.33","Gross Margin on Sales":"-599.260000000002","Cost-of-Goods Sold":"-10189.71","Average Price":"34.1452259559676","Last Price":"34.95","Cumulative COGS":"-49296.5","Cumulative Gross Margin":"-368.910000000001","GM Percentage":"-0.062485076299861","Cumulative GM Percentage":"-0.00753991766199808"},{"trn":"52131014","sym":"GHI","tDate":"2013-10-14","qty":"-91.00","price_unit":"33.12","price_extended":"-3013.92","Inventory-On-Hand":"772","Inventory Cost":"26386.07","Gross Margin on Sales":"-67.3399999999983","Cost-of-Goods Sold":"-3081.26","Average Price":"34.1788471502591","Last Price":"34.95","Cumulative COGS":"-52377.76","Cumulative Gross Margin":"-436.249999999999","GM Percentage":"-0.0223429951690816","Cumulative GM Percentage":"-0.00839887019072028"},{"trn":"73131028","sym":"GHI","tDate":"2013-10-28","qty":"-46.00","price_unit":"34.65","price_extended":"-1593.90","Inventory-On-Hand":"726","Inventory Cost":"24835.71","Gross Margin on Sales":"43.5399999999995","Cost-of-Goods Sold":"-1550.36","Average Price":"34.2089669421488","Last Price":"34.95","Cumulative COGS":"-53928.12","Cumulative Gross Margin":"-392.71","GM Percentage":"0.0273166447079487","Cumulative GM Percentage":"-0.00733551867819822"},{"trn":"50131103","sym":"GHI","tDate":"2013-11-03","qty":"-246.00","price_unit":"35.61","price_extended":"-8760.06","Inventory-On-Hand":"480","Inventory Cost":"16594.71","Gross Margin on Sales":"519.059999999999","Cost-of-Goods Sold":"-8241","Average Price":"34.5723125","Last Price":"34.95","Cumulative COGS":"-62169.12","Cumulative Gross Margin":"126.35","GM Percentage":"0.0592530188149396","Cumulative GM Percentage":"0.00202823736621619"},{"trn":"87131116","sym":"GHI","tDate":"2013-11-16","qty":"-320.00","price_unit":"34.16","price_extended":"-10931.20","Inventory-On-Hand":"160","Inventory Cost":"5633.6","Gross Margin on Sales":"-29.909999999998","Cost-of-Goods Sold":"-10961.11","Average Price":"35.21","Last Price":"34.95","Cumulative COGS":"-73130.23","Cumulative Gross Margin":"96.4400000000019","GM Percentage":"-0.00273620462529256","Cumulative GM Percentage":"0.00131700649503797"},{"trn":"94131117","sym":"GHI","tDate":"2013-11-17","qty":"-92.00","price_unit":"32.65","price_extended":"-3003.80","Inventory-On-Hand":"68","Inventory Cost":"2394.28","Gross Margin on Sales":"-235.52","Cost-of-Goods Sold":"-3239.32","Average Price":"35.21","Last Price":"34.95","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"-0.0784073506891272","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"81131123","sym":"GHI","tDate":"2013-11-23","qty":"187.00","price_unit":"33.86","price_extended":"6331.82","Inventory-On-Hand":"255","Inventory Cost":"8726.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.22","Last Price":"33.86","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"51131206","sym":"GHI","tDate":"2013-12-06","qty":"85.00","price_unit":"33.64","price_extended":"2859.40","Inventory-On-Hand":"340","Inventory Cost":"11585.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.075","Last Price":"33.64","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"75131216","sym":"GHI","tDate":"2013-12-16","qty":"500.00","price_unit":"33.55","price_extended":"16775.00","Inventory-On-Hand":"840","Inventory Cost":"28360.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7625","Last Price":"33.55","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"13131221","sym":"GHI","tDate":"2013-12-21","qty":"72.00","price_unit":"34.38","price_extended":"2475.36","Inventory-On-Hand":"912","Inventory Cost":"30835.86","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.81125","Last Price":"34.38","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"65131227","sym":"GHI","tDate":"2013-12-27","qty":"376.00","price_unit":"33.49","price_extended":"12592.24","Inventory-On-Hand":"1288","Inventory Cost":"43428.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7174689440994","Last Price":"33.49","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"53140102","sym":"GHI","tDate":"2014-01-02","qty":"396.00","price_unit":"35.52","price_extended":"14065.92","Inventory-On-Hand":"1684","Inventory Cost":"57494.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1413420427553","Last Price":"35.52","Cumulative COGS":"-76369.55","Cumulative Gross Margin":"-139.079999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00182446730290393"},{"trn":"18140125","sym":"GHI","tDate":"2014-01-25","qty":"-78.00","price_unit":"35.46","price_extended":"-2765.88","Inventory-On-Hand":"1606","Inventory Cost":"54723.46","Gross Margin on Sales":"-4.67999999999756","Cost-of-Goods Sold":"-2770.56","Average Price":"34.0743835616438","Last Price":"35.52","Cumulative COGS":"-79140.11","Cumulative Gross Margin":"-143.759999999996","GM Percentage":"-0.00169204737732568","Cumulative GM Percentage":"-0.00181983091623849"},{"trn":"37130220","sym":"XYZ","tDate":"2013-02-20","qty":"528.00","price_unit":"23.54","price_extended":"12429.12","Inventory-On-Hand":"528","Inventory Cost":"12429.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.54","Last Price":"23.54","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"44130227","sym":"XYZ","tDate":"2013-02-27","qty":"357.00","price_unit":"22.86","price_extended":"8161.02","Inventory-On-Hand":"885","Inventory Cost":"20590.14","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.2656949152542","Last Price":"22.86","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"67130302","sym":"XYZ","tDate":"2013-03-02","qty":"9.00","price_unit":"24.04","price_extended":"216.36","Inventory-On-Hand":"894","Inventory Cost":"20806.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.2734899328859","Last Price":"24.04","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"trn":"38130311","sym":"XYZ","tDate":"2013-03-11","qty":"-193.00","price_unit":"24.90","price_extended":"-4805.70","Inventory-On-Hand":"701","Inventory Cost":"16383.9","Gross Margin on Sales":"383.100000000001","Cost-of-Goods Sold":"-4422.6","Average Price":"23.372182596291","Last Price":"24.04","Cumulative COGS":"-4422.6","Cumulative Gross Margin":"383.100000000001","GM Percentage":"0.0797178350708536","Cumulative GM Percentage":"0.0797178350708536"},{"trn":"59130320","sym":"XYZ","tDate":"2013-03-20","qty":"-20.00","price_unit":"23.59","price_extended":"-471.80","Inventory-On-Hand":"681","Inventory Cost":"15926.7","Gross Margin on Sales":"14.5999999999993","Cost-of-Goods Sold":"-457.200000000001","Average Price":"23.3872246696035","Last Price":"24.04","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"0.0309453158117831","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"35130321","sym":"XYZ","tDate":"2013-03-21","qty":"275.00","price_unit":"24.83","price_extended":"6828.25","Inventory-On-Hand":"956","Inventory Cost":"22754.95","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8022489539749","Last Price":"24.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"98130413","sym":"XYZ","tDate":"2013-04-13","qty":"243.00","price_unit":"24.25","price_extended":"5892.75","Inventory-On-Hand":"1199","Inventory Cost":"28647.7","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8929941618015","Last Price":"24.25","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"24130418","sym":"XYZ","tDate":"2013-04-18","qty":"275.00","price_unit":"24.83","price_extended":"6828.25","Inventory-On-Hand":"1474","Inventory Cost":"35475.95","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0678086838535","Last Price":"24.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"60130419","sym":"XYZ","tDate":"2013-04-19","qty":"277.00","price_unit":"22.83","price_extended":"6323.91","Inventory-On-Hand":"1751","Inventory Cost":"41799.86","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8719931467733","Last Price":"22.83","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"83130428","sym":"XYZ","tDate":"2013-04-28","qty":"142.00","price_unit":"23.13","price_extended":"3284.46","Inventory-On-Hand":"1893","Inventory Cost":"45084.32","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8163338615954","Last Price":"23.13","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"34130507","sym":"XYZ","tDate":"2013-05-07","qty":"55.00","price_unit":"23.43","price_extended":"1288.65","Inventory-On-Hand":"1948","Inventory Cost":"46372.97","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8054260780287","Last Price":"23.43","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"99130515","sym":"XYZ","tDate":"2013-05-15","qty":"97.00","price_unit":"25.13","price_extended":"2437.61","Inventory-On-Hand":"2045","Inventory Cost":"48810.58","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8682542787286","Last Price":"25.13","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"19130516","sym":"XYZ","tDate":"2013-05-16","qty":"315.00","price_unit":"23.57","price_extended":"7424.55","Inventory-On-Hand":"2360","Inventory Cost":"56235.13","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8284449152542","Last Price":"23.57","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"30130519","sym":"XYZ","tDate":"2013-05-19","qty":"467.00","price_unit":"23.15","price_extended":"10811.05","Inventory-On-Hand":"2827","Inventory Cost":"67046.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7163707110011","Last Price":"23.15","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"29130602","sym":"XYZ","tDate":"2013-06-02","qty":"114.00","price_unit":"24.29","price_extended":"2769.06","Inventory-On-Hand":"2941","Inventory Cost":"69815.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.738605916355","Last Price":"24.29","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"91130615","sym":"XYZ","tDate":"2013-06-15","qty":"545.00","price_unit":"23.88","price_extended":"13014.60","Inventory-On-Hand":"3486","Inventory Cost":"82829.84","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.760711417097","Last Price":"23.88","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"23130619","sym":"XYZ","tDate":"2013-06-19","qty":"296.00","price_unit":"23.46","price_extended":"6944.16","Inventory-On-Hand":"3782","Inventory Cost":"89774","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.737176097303","Last Price":"23.46","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"47130619","sym":"XYZ","tDate":"2013-06-19","qty":"413.00","price_unit":"25.18","price_extended":"10399.34","Inventory-On-Hand":"4195","Inventory Cost":"100173.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8792228843862","Last Price":"25.18","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"74130619","sym":"XYZ","tDate":"2013-06-19","qty":"202.00","price_unit":"22.95","price_extended":"4635.90","Inventory-On-Hand":"4397","Inventory Cost":"104809.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8365340004549","Last Price":"22.95","Cumulative COGS":"-4879.8","Cumulative Gross Margin":"397.700000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0753576504026529"},{"trn":"55130630","sym":"XYZ","tDate":"2013-06-30","qty":"-272.00","price_unit":"23.45","price_extended":"-6378.40","Inventory-On-Hand":"4125","Inventory Cost":"98410.74","Gross Margin on Sales":"-20.0999999999858","Cost-of-Goods Sold":"-6398.49999999999","Average Price":"23.8571490909091","Last Price":"22.95","Cumulative COGS":"-11278.3","Cumulative Gross Margin":"377.600000000015","GM Percentage":"-0.00315126050419946","Cumulative GM Percentage":"0.0323956108065456"},{"trn":"14130705","sym":"XYZ","tDate":"2013-07-05","qty":"-277.00","price_unit":"25.01","price_extended":"-6927.77","Inventory-On-Hand":"3848","Inventory Cost":"91435.88","Gross Margin on Sales":"-47.0900000000001","Cost-of-Goods Sold":"-6974.86","Average Price":"23.7619230769231","Last Price":"22.95","Cumulative COGS":"-18253.16","Cumulative Gross Margin":"330.510000000015","GM Percentage":"-0.00679728108756499","Cumulative GM Percentage":"0.0177849692767906"},{"trn":"5130706","sym":"XYZ","tDate":"2013-07-06","qty":"-170.00","price_unit":"23.46","price_extended":"-3988.20","Inventory-On-Hand":"3678","Inventory Cost":"87334.16","Gross Margin on Sales":"-113.520000000016","Cost-of-Goods Sold":"-4101.72000000002","Average Price":"23.7450135943448","Last Price":"22.95","Cumulative COGS":"-22354.88","Cumulative Gross Margin":"216.989999999999","GM Percentage":"-0.0284639687076917","Cumulative GM Percentage":"0.00961329300585192"},{"trn":"58130722","sym":"XYZ","tDate":"2013-07-22","qty":"-88.00","price_unit":"24.64","price_extended":"-2168.32","Inventory-On-Hand":"3590","Inventory Cost":"85269.68","Gross Margin on Sales":"103.840000000004","Cost-of-Goods Sold":"-2064.48","Average Price":"23.752","Last Price":"22.95","Cumulative COGS":"-24419.36","Cumulative Gross Margin":"320.830000000003","GM Percentage":"0.0478896103896123","Cumulative GM Percentage":"0.0129679683139056"},{"trn":"57130813","sym":"XYZ","tDate":"2013-08-13","qty":"-163.00","price_unit":"23.65","price_extended":"-3854.95","Inventory-On-Hand":"3427","Inventory Cost":"81420.92","Gross Margin on Sales":"6.19000000000506","Cost-of-Goods Sold":"-3848.75999999999","Average Price":"23.7586577181208","Last Price":"22.95","Cumulative COGS":"-28268.12","Cumulative Gross Margin":"327.020000000008","GM Percentage":"0.0016057277007497","Cumulative GM Percentage":"0.0114362090900764"},{"trn":"54130831","sym":"XYZ","tDate":"2013-08-31","qty":"-61.00","price_unit":"23.23","price_extended":"-1417.03","Inventory-On-Hand":"3366","Inventory Cost":"79964.24","Gross Margin on Sales":"-39.6500000000076","Cost-of-Goods Sold":"-1456.68000000001","Average Price":"23.756458704694","Last Price":"22.95","Cumulative COGS":"-29724.8","Cumulative Gross Margin":"287.37","GM Percentage":"-0.0279810589754681","Cumulative GM Percentage":"0.00957511569473318"},{"trn":"11130906","sym":"XYZ","tDate":"2013-09-06","qty":"-13.00","price_unit":"23.97","price_extended":"-311.61","Inventory-On-Hand":"3353","Inventory Cost":"79653.8","Gross Margin on Sales":"1.16999999999769","Cost-of-Goods Sold":"-310.440000000002","Average Price":"23.755979719654","Last Price":"22.95","Cumulative COGS":"-30035.24","Cumulative Gross Margin":"288.539999999998","GM Percentage":"0.00375469336670096","Cumulative GM Percentage":"0.00951530449040318"},{"trn":"27130906","sym":"XYZ","tDate":"2013-09-06","qty":"-147.00","price_unit":"23.81","price_extended":"-3500.07","Inventory-On-Hand":"3206","Inventory Cost":"76143.44","Gross Margin on Sales":"-10.2900000000004","Cost-of-Goods Sold":"-3510.36","Average Price":"23.7502932002495","Last Price":"22.95","Cumulative COGS":"-33545.6","Cumulative Gross Margin":"278.249999999998","GM Percentage":"-0.0029399412011761","Cumulative GM Percentage":"0.00822644376675031"},{"trn":"36130917","sym":"XYZ","tDate":"2013-09-17","qty":"92.00","price_unit":"24.60","price_extended":"2263.20","Inventory-On-Hand":"3298","Inventory Cost":"78406.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7739963614312","Last Price":"24.6","Cumulative COGS":"-33545.6","Cumulative Gross Margin":"278.249999999998","GM Percentage":"NULL","Cumulative GM Percentage":"0.00822644376675031"},{"trn":"92130924","sym":"XYZ","tDate":"2013-09-24","qty":"-248.00","price_unit":"24.58","price_extended":"-6095.84","Inventory-On-Hand":"3050","Inventory Cost":"72418.16","Gross Margin on Sales":"107.360000000004","Cost-of-Goods Sold":"-5988.48","Average Price":"23.7436590163934","Last Price":"24.6","Cumulative COGS":"-39534.08","Cumulative Gross Margin":"385.610000000002","GM Percentage":"0.0176120108139328","Cumulative GM Percentage":"0.0096596441505433"},{"trn":"42131011","sym":"XYZ","tDate":"2013-10-11","qty":"-250.00","price_unit":"23.12","price_extended":"-5780.00","Inventory-On-Hand":"2800","Inventory Cost":"66421.13","Gross Margin on Sales":"-217.029999999999","Cost-of-Goods Sold":"-5997.03","Average Price":"23.7218321428571","Last Price":"24.6","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"-0.0375484429065742","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"22131012","sym":"XYZ","tDate":"2013-10-12","qty":"596.00","price_unit":"23.16","price_extended":"13803.36","Inventory-On-Hand":"3396","Inventory Cost":"80224.49","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.623230270907","Last Price":"23.16","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"40131013","sym":"XYZ","tDate":"2013-10-13","qty":"359.00","price_unit":"23.91","price_extended":"8583.69","Inventory-On-Hand":"3755","Inventory Cost":"88808.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6506471371505","Last Price":"23.91","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"1131019","sym":"XYZ","tDate":"2013-10-19","qty":"424.00","price_unit":"25.13","price_extended":"10655.12","Inventory-On-Hand":"4179","Inventory Cost":"99463.3","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8007418042594","Last Price":"25.13","Cumulative COGS":"-45531.11","Cumulative Gross Margin":"168.580000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.00368886528551951"},{"trn":"9131025","sym":"XYZ","tDate":"2013-10-25","qty":"-153.00","price_unit":"24.31","price_extended":"-3719.43","Inventory-On-Hand":"4026","Inventory Cost":"95618.41","Gross Margin on Sales":"-125.46","Cost-of-Goods Sold":"-3844.89","Average Price":"23.7502260307998","Last Price":"25.13","Cumulative COGS":"-49376","Cumulative Gross Margin":"43.1200000000035","GM Percentage":"-0.0337309749074454","Cumulative GM Percentage":"0.000872536783334132"},{"trn":"62131027","sym":"XYZ","tDate":"2013-10-27","qty":"-248.00","price_unit":"24.71","price_extended":"-6128.08","Inventory-On-Hand":"3778","Inventory Cost":"89386.17","Gross Margin on Sales":"-104.159999999991","Cost-of-Goods Sold":"-6232.23999999999","Average Price":"23.6596532556908","Last Price":"25.13","Cumulative COGS":"-55608.24","Cumulative Gross Margin":"-61.0399999999873","GM Percentage":"-0.0169971671388087","Cumulative GM Percentage":"-0.00109888527234473"},{"trn":"45131030","sym":"XYZ","tDate":"2013-10-30","qty":"-350.00","price_unit":"23.36","price_extended":"-8176.00","Inventory-On-Hand":"3428","Inventory Cost":"80989.61","Gross Margin on Sales":"-220.560000000012","Cost-of-Goods Sold":"-8396.56000000001","Average Price":"23.6259072345391","Last Price":"25.13","Cumulative COGS":"-64004.8","Cumulative Gross Margin":"-281.6","GM Percentage":"-0.0269765166340524","Cumulative GM Percentage":"-0.00441911266226429"},{"trn":"21131103","sym":"XYZ","tDate":"2013-11-03","qty":"-326.00","price_unit":"23.24","price_extended":"-7576.24","Inventory-On-Hand":"3102","Inventory Cost":"73415.45","Gross Margin on Sales":"2.08000000001084","Cost-of-Goods Sold":"-7574.15999999999","Average Price":"23.6671341070277","Last Price":"25.13","Cumulative COGS":"-71578.96","Cumulative Gross Margin":"-279.519999999989","GM Percentage":"0.00027454251713394","Cumulative GM Percentage":"-0.00392036739699482"},{"trn":"97131125","sym":"XYZ","tDate":"2013-11-25","qty":"-278.00","price_unit":"23.18","price_extended":"-6444.04","Inventory-On-Hand":"2824","Inventory Cost":"66976.97","Gross Margin on Sales":"5.55999999998949","Cost-of-Goods Sold":"-6438.48000000001","Average Price":"23.7170573654391","Last Price":"25.13","Cumulative COGS":"-78017.44","Cumulative Gross Margin":"-273.959999999999","GM Percentage":"0.000862812769627359","Cumulative GM Percentage":"-0.00352389679494665"},{"trn":"28131209","sym":"XYZ","tDate":"2013-12-09","qty":"315.00","price_unit":"24.46","price_extended":"7704.90","Inventory-On-Hand":"3139","Inventory Cost":"74681.87","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.791611978337","Last Price":"24.46","Cumulative COGS":"-78017.44","Cumulative Gross Margin":"-273.959999999999","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00352389679494665"},{"trn":"79131223","sym":"XYZ","tDate":"2013-12-23","qty":"-376.00","price_unit":"25.12","price_extended":"-9445.12","Inventory-On-Hand":"2763","Inventory Cost":"65564.58","Gross Margin on Sales":"327.830000000007","Cost-of-Goods Sold":"-9117.28999999999","Average Price":"23.7294896851249","Last Price":"24.46","Cumulative COGS":"-87134.73","Cumulative Gross Margin":"53.870000000008","GM Percentage":"0.0347089290554283","Cumulative GM Percentage":"0.000617856004110721"},{"trn":"33140102","sym":"XYZ","tDate":"2014-01-02","qty":"-196.00","price_unit":"22.98","price_extended":"-4504.08","Inventory-On-Hand":"2567","Inventory Cost":"61027.18","Gross Margin on Sales":"-33.3199999999943","Cost-of-Goods Sold":"-4537.39999999999","Average Price":"23.7737358784573","Last Price":"24.46","Cumulative COGS":"-91672.13","Cumulative Gross Margin":"20.5500000000138","GM Percentage":"-0.00739773716274894","Cumulative GM Percentage":"0.000224118217506717"},{"trn":"84140104","sym":"XYZ","tDate":"2014-01-04","qty":"261.00","price_unit":"24.46","price_extended":"6384.06","Inventory-On-Hand":"2828","Inventory Cost":"67411.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.837072135785","Last Price":"24.46","Cumulative COGS":"-91672.13","Cumulative Gross Margin":"20.5500000000138","GM Percentage":"NULL","Cumulative GM Percentage":"0.000224118217506717"},{"trn":"64140109","sym":"XYZ","tDate":"2014-01-09","qty":"-253.00","price_unit":"24.46","price_extended":"-6188.38","Inventory-On-Hand":"2575","Inventory Cost":"61222.86","Gross Margin on Sales":"2.72848410531878E-12","Cost-of-Goods Sold":"-6188.38","Average Price":"23.7758679611651","Last Price":"24.46","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"4.40904421725683E-16","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"78140112","sym":"XYZ","tDate":"2014-01-12","qty":"332.00","price_unit":"24.28","price_extended":"8060.96","Inventory-On-Hand":"2907","Inventory Cost":"69283.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8334434124527","Last Price":"24.28","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"80140126","sym":"XYZ","tDate":"2014-01-26","qty":"404.00","price_unit":"24.23","price_extended":"9788.92","Inventory-On-Hand":"3311","Inventory Cost":"79072.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8818302627605","Last Price":"24.23","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"82140131","sym":"XYZ","tDate":"2014-01-31","qty":"548.00","price_unit":"23.65","price_extended":"12960.20","Inventory-On-Hand":"3859","Inventory Cost":"92032.94","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8489090437937","Last Price":"23.65","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"66140203","sym":"XYZ","tDate":"2014-02-03","qty":"459.00","price_unit":"23.70","price_extended":"10878.30","Inventory-On-Hand":"4318","Inventory Cost":"102911.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8330801296897","Last Price":"23.7","Cumulative COGS":"-97860.51","Cumulative Gross Margin":"20.5500000000165","GM Percentage":"NULL","Cumulative GM Percentage":"0.000209948686702172"},{"trn":"72140204","sym":"XYZ","tDate":"2014-02-04","qty":"-208.00","price_unit":"24.36","price_extended":"-5066.88","Inventory-On-Hand":"4110","Inventory Cost":"97981.64","Gross Margin on Sales":"137.279999999994","Cost-of-Goods Sold":"-4929.60000000001","Average Price":"23.8398150851582","Last Price":"23.7","Cumulative COGS":"-102790.11","Cumulative Gross Margin":"157.830000000011","GM Percentage":"0.0270935960591122","Cumulative GM Percentage":"0.00153310498490801"},{"trn":"31140205","sym":"XYZ","tDate":"2014-02-05","qty":"42.00","price_unit":"24.39","price_extended":"1024.38","Inventory-On-Hand":"4152","Inventory Cost":"99006.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.845380539499","Last Price":"24.39","Cumulative COGS":"-102790.11","Cumulative Gross Margin":"157.830000000011","GM Percentage":"NULL","Cumulative GM Percentage":"0.00153310498490801"}]}
Example #4
In this example we require multiple columns to uniquely identify the inventory items and there are no unique transaction identifiers.
--Put some data into #p
SELECT *
INTO #p
FROM ( VALUES ('ZYX', 'Coffee Mug', 'Ceramic', '8 oz', 'Black', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '12 oz', 'Black', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '16 oz', 'Black', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '20 oz', 'Black', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '8 oz', 'White', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '12 oz', 'White', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '16 oz', 'White', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Ceramic', '20 oz', 'White', '2017-01-15', 50, 1.12, 56),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'Black', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '12 oz', 'Black', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '16 oz', 'Black', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '20 oz', 'Black', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '12 oz', 'White', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '16 oz', 'White', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Plastic', '20 oz', 'White', '2017-01-15', 50, 0.89, 44.5),
('ZYX', 'Coffee Mug', 'Ceramic', '8 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '12 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '16 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '20 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '8 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '12 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '16 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Ceramic', '20 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '12 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '16 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '20 oz', 'Black', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '12 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '16 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '20 oz', 'White', '2017-02-15', 50, 1.15, 57.5),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-01-16', -5, 2.95, -14.75),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-01-23', -2, 2.95, -5.9),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-01-24', -1, 2.95, -2.95),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-02-01', -3, 2.95, -8.85),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-02-08', -7, 2.95, -20.65),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-02-15', -6, 2.95, -17.7),
('ZYX', 'Coffee Mug', 'Plastic', '8 oz', 'White', '2017-02-22', -2, 2.95, -5.9)) n ([Manufacturer],
[Description],
[Material],
[Size], [Color],
[Date], [qty],
[unit price],
[extended price]);
--Copy the #p data into #p2 and put it in order for LIFO processing
SELECT IDENTITY(int, 1, 1) as ID,
ROW_NUMBER() OVER (PARTITION BY [Manufacturer],
[Description],
[Material],
[Size],
[Color]
ORDER BY [Manufacturer],
[Description],
[Material],
[Size],
[Color],
[Date],
qty DESC) as rn,
#p.*
INTO #p2
FROM #p
ORDER BY [Manufacturer],
[Description],
[Material],
[Size],
[Color],
[Date],
qty DESC;
--Put the tvf results into the #LIFO table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #LIFO
FROM wct.LIFOtvf('SELECT ID, rn,qty,[extended price] FROM #p2 ORDER BY ID');
--JOIN to the source data to produce the inventory output
SELECT #p2.[Manufacturer],
#p2.[Description],
#p2.[Material],
#p2.[Size],
#p2.[Color],
#p2.[Date],
#p2.[qty],
#p2.[unit price],
#p2.[extended price],
l.[QTY] as [Inventory-On-Hand],
l.[EB] as [Inventory Cost],
l.[GM] as [Gross Margin on Sales],
l.[COGS] as [Cost-of-Goods Sold],
l.[UP] as [Average Price],
l.[LP] as [Last Price],
l.[COGSC] as [Cumulative COGS],
l.[GMC] as [Cumulative Gross Margin],
l.[GMP] as [GM Percentage],
l.[CGMP] as [Cumulative GM Percentage]
FROM #p2
INNER JOIN #LIFO l
ON #p2.ID = l.[ID]
ORDER BY #p2.id;
This produces the following result.
{"columns":[{"field":"Manufacturer"},{"field":"Description"},{"field":"Material"},{"field":"Size"},{"field":"Color"},{"field":"Date","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"qty","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"unit price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"extended price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory-On-Hand","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Inventory Cost","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Gross Margin on Sales","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cost-of-Goods Sold","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Average Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Last Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative COGS","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Cumulative Gross Margin","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GM Percentage"},{"field":"Cumulative GM Percentage"}],"rows":[{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"12 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"12 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"12 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"12 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"16 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"16 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"16 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"16 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"20 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"20 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"20 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"20 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"8 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"8 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"8 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"1.12","extended price":"56.00","Inventory-On-Hand":"50","Inventory Cost":"56","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.12","Last Price":"1.12","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Ceramic","Size":"8 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"113.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.135","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"12 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"12 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"12 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"12 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"16 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"16 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"16 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"16 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"20 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"20 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"20 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"20 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"Black","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"Black","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"100","Inventory Cost":"102","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.02","Last Price":"1.15","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-01-15","qty":"50","unit price":"0.89","extended price":"44.50","Inventory-On-Hand":"50","Inventory Cost":"44.5","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"0","Cumulative Gross Margin":"0","GM Percentage":"NULL","Cumulative GM Percentage":"NULL"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-01-16","qty":"-5","unit price":"2.95","extended price":"-14.75","Inventory-On-Hand":"45","Inventory Cost":"40.05","Gross Margin on Sales":"10.3","Cost-of-Goods Sold":"-4.45","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-4.45","Cumulative Gross Margin":"10.3","GM Percentage":"0.698305084745763","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-01-23","qty":"-2","unit price":"2.95","extended price":"-5.90","Inventory-On-Hand":"43","Inventory Cost":"38.27","Gross Margin on Sales":"4.11999999999999","Cost-of-Goods Sold":"-1.78000000000001","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-6.23","Cumulative Gross Margin":"14.42","GM Percentage":"0.698305084745761","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-01-24","qty":"-1","unit price":"2.95","extended price":"-2.95","Inventory-On-Hand":"42","Inventory Cost":"37.38","Gross Margin on Sales":"2.06","Cost-of-Goods Sold":"-0.890000000000001","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-7.12","Cumulative Gross Margin":"16.48","GM Percentage":"0.698305084745763","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-02-01","qty":"-3","unit price":"2.95","extended price":"-8.85","Inventory-On-Hand":"39","Inventory Cost":"34.71","Gross Margin on Sales":"6.18","Cost-of-Goods Sold":"-2.67","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-9.79000000000001","Cumulative Gross Margin":"22.66","GM Percentage":"0.698305084745762","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-02-08","qty":"-7","unit price":"2.95","extended price":"-20.65","Inventory-On-Hand":"32","Inventory Cost":"28.48","Gross Margin on Sales":"14.42","Cost-of-Goods Sold":"-6.23","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-16.02","Cumulative Gross Margin":"37.08","GM Percentage":"0.698305084745763","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-02-15","qty":"50","unit price":"1.15","extended price":"57.50","Inventory-On-Hand":"82","Inventory Cost":"85.98","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"1.04853658536585","Last Price":"1.15","Cumulative COGS":"-16.02","Cumulative Gross Margin":"37.08","GM Percentage":"NULL","Cumulative GM Percentage":"0.698305084745763"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-02-15","qty":"-6","unit price":"2.95","extended price":"-17.70","Inventory-On-Hand":"76","Inventory Cost":"79.08","Gross Margin on Sales":"10.8","Cost-of-Goods Sold":"-6.89999999999999","Average Price":"1.04052631578947","Last Price":"1.15","Cumulative COGS":"-22.92","Cumulative Gross Margin":"47.88","GM Percentage":"0.610169491525424","Cumulative GM Percentage":"0.676271186440678"},{"Manufacturer":"ZYX","Description":"Coffee Mug","Material":"Plastic","Size":"8 oz","Color":"White","Date":"2017-02-22","qty":"-2","unit price":"2.95","extended price":"-5.90","Inventory-On-Hand":"74","Inventory Cost":"76.78","Gross Margin on Sales":"3.6","Cost-of-Goods Sold":"-2.3","Average Price":"1.03756756756757","Last Price":"1.15","Cumulative COGS":"-25.22","Cumulative Gross Margin":"51.48","GM Percentage":"0.610169491525424","Cumulative GM Percentage":"0.671186440677966"}]}
See Also
FIFO - Calculate FIFO (first in, first out) values in an ordered resultant table.
FIFOend - Calculate the ending FIFO balances in an ordered resultant table.
FIFOtvf - Calculate running FIFO (First In, First Out) values in an ordered resultant table.
LIFO - Calculate LIFO (last in, first out) values in an ordered resultant table.
LIFOend - Calculate the ending LIFO balances in an ordered resultant table.
WAC - Calculate running weighted average cost in an ordered resultant table.
WACtvf - Calculate running weighted-average cost values in an ordered resultant table.