FIFOtvf
Updated 2023-10-12 12:36:03.583000
Syntax
SELECT * FROM [westclintech].[wct].[FIFOtvf] (
<@DataQuery, nvarchar(max),>)
Description
Use the table-valued function FIFOtvf to calculate running FIFO (First In, First Out) values in an ordered resultant table. FIFOtvf calculates balances for each value from the first value to the last value in the ordered group or partition. FIFOtvf 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.
FIFOtvf supports both long and short inventory positions. In other words, if the quantity on hand falls below the zero, FIFOtvf calculates from the last sale or withdrawal transaction, rather than from the last purchases or additions to inventory.
FIFOtvf assumes that the quantity, i.e., the number of units of the transaction, and the monetary value of the transaction have the same sign. FIFOtvf adds NULL values to the inventory at the last price.
FIFOtvf requires monotonically ascending row numbers within a partition.
FIFOtvf 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": "319ab34a-0744-4387-80f6-515828e08341", "colName": "ID", "colDatatype": "sql_variant", "colDesc": "unique transaction identifier"}, {"id": "8ca41c26-7856-4227-9971-5d07eb437838", "colName": "QTY", "colDatatype": "float", "colDesc": "inventory quantity"}, {"id": "538fa033-0e2d-41db-8927-eaec0795f979", "colName": "EB", "colDatatype": "float", "colDesc": "inventory value"}, {"id": "b0f880d1-5a27-4f54-83b2-f76c959010b7", "colName": "GM", "colDatatype": "float", "colDesc": "gross margin on sale"}, {"id": "5f1ab135-7fa7-4004-a826-79d34cd0da8e", "colName": "COGS", "colDatatype": "float", "colDesc": "cost of goods sold"}, {"id": "3a28f8bc-1b1b-4c42-a7f7-6e0eccc6674d", "colName": "UP", "colDatatype": "float", "colDesc": "average inventory price per unit"}, {"id": "e9e58a49-8cbc-4e39-9e17-fb2669878685", "colName": "LP", "colDatatype": "float", "colDesc": "last item added price"}, {"id": "9c88a74c-d300-4b0c-9d62-4ac9bb35c648", "colName": "COGSC", "colDatatype": "float", "colDesc": "cumulative cost of goods sold"}, {"id": "78b381f4-c0cc-4c00-8389-853a0d41ace8", "colName": "GMC", "colDatatype": "float", "colDesc": "cumulative gross margin"}, {"id": "e27261ef-92e5-46ad-a420-de833129466e", "colName": "GMP", "colDatatype": "float", "colDesc": "gross margin percentage"}, {"id": "85fa1d81-3847-4371-9b85-31afb9382c66", "colName": "GMPC", "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 FIFO 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 FIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #fifo
FROM wct.FIFOtvf('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,
f.[QTY] as [Inventory-On-Hand],
f.[EB] as [Inventory Cost],
f.[GM] as [Gross Margin on Sales],
f.[COGS] as [Cost-of-Goods Sold],
f.[UP] as [Average Price],
f.[LP] as [Last Price],
f.[COGSC] as [Cumulative COGS],
f.[GMC] as [Cumulative Gross Margin],
f.[GMP] as [GM Percentage],
f.[CGMP] as [Cumulative GM Percentage]
FROM #c c
INNER JOIN #FIFO f
ON c.trn = f.[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":"3077.75","Gross Margin on Sales":"61.23","Cost-of-Goods Sold":"-2006.46","Average Price":"12.9317226890756","Last Price":"13.01","Cumulative COGS":"-2006.46","Cumulative Gross Margin":"61.23","GM Percentage":"0.0296127562642369","Cumulative GM Percentage":"0.0296127562642369"},{"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":"2272.61","Gross Margin on Sales":"-10.7100000000004","Cost-of-Goods Sold":"-805.14","Average Price":"12.9863428571429","Last Price":"13.01","Cumulative COGS":"-2811.6","Cumulative Gross Margin":"50.5199999999996","GM Percentage":"-0.0134813639968284","Cumulative GM Percentage":"0.0176512515198523"},{"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":"8467.55","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2720219435737","Last Price":"13.38","Cumulative COGS":"-2811.6","Cumulative Gross Margin":"50.5199999999996","GM Percentage":"NULL","Cumulative GM Percentage":"0.0176512515198523"},{"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":"7274.77","Gross Margin on Sales":"62.1000000000004","Cost-of-Goods Sold":"-1192.78","Average Price":"13.3237545787546","Last Price":"13.38","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"0.0494868035190619","Cumulative GM Percentage":"0.027354870051008"},{"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":"11142.81","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2023815165877","Last Price":"12.98","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"NULL","Cumulative GM Percentage":"0.027354870051008"},{"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":"14193.09","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2274836905871","Last Price":"13.32","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"NULL","Cumulative GM Percentage":"0.027354870051008"},{"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":"11668.22","Gross Margin on Sales":"51.7199999999993","Cost-of-Goods Sold":"-2524.87","Average Price":"13.2292743764172","Last Price":"13.32","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"0.0200730422768075","Cumulative GM Percentage":"0.0245518473644187"},{"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":"14712.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1359285714286","Last Price":"12.79","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"18654.78","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1556981664316","Last Price":"13.23","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"20347.38","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1443023255814","Last Price":"13.02","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"24394.47","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1082590005373","Last Price":"12.93","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"20032.59","Gross Margin on Sales":"-211.899999999998","Cost-of-Goods Sold":"-4361.88","Average Price":"13.0505472312704","Last Price":"12.93","Cumulative COGS":"-10891.13","Cumulative Gross Margin":"-47.5599999999985","GM Percentage":"-0.0510604870384912","Cumulative GM Percentage":"-0.00438600940465165"},{"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":"17074.53","Gross Margin on Sales":"99.6299999999987","Cost-of-Goods Sold":"-2958.06","Average Price":"13.0539220183486","Last Price":"12.93","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"0.0325834208176757","Cumulative GM Percentage":"0.0037457036268655"},{"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":"25250.88","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2411536444677","Last Price":"13.65","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0037457036268655"},{"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":"26321.33","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2534390735146","Last Price":"13.55","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0037457036268655"},{"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":"21244.02","Gross Margin on Sales":"191.590000000006","Cost-of-Goods Sold":"-5077.30999999999","Average Price":"13.2775125","Last Price":"13.55","Cumulative COGS":"-18926.5","Cumulative Gross Margin":"243.660000000006","GM Percentage":"0.0363624285904089","Cumulative GM Percentage":"0.0127103790474365"},{"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":"27462.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1397703349282","Last Price":"12.69","Cumulative COGS":"-18926.5","Cumulative Gross Margin":"243.660000000006","GM Percentage":"NULL","Cumulative GM Percentage":"0.0127103790474365"},{"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":"24869.3","Gross Margin on Sales":"21.0599999999968","Cost-of-Goods Sold":"-2592.82","Average Price":"13.1722987288136","Last Price":"12.69","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"0.00805698807902305","Cumulative GM Percentage":"0.0121520158795156"},{"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":"28223.33","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2069864295742","Last Price":"13.47","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"30721.65","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2192986230637","Last Price":"13.36","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"31064.01","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2131050616759","Last Price":"12.68","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"25980.12","Gross Margin on Sales":"-297.49","Cost-of-Goods Sold":"-5083.89","Average Price":"13.2214351145038","Last Price":"12.68","Cumulative COGS":"-26603.21","Cumulative Gross Margin":"-32.7699999999971","GM Percentage":"-0.0621531840213939","Cumulative GM Percentage":"-0.00123332545490391"},{"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":"24103.38","Gross Margin on Sales":"35.810000000002","Cost-of-Goods Sold":"-1876.74","Average Price":"13.2436153846154","Last Price":"12.68","Cumulative COGS":"-28479.95","Cumulative Gross Margin":"3.04000000000485","GM Percentage":"0.0187236934982102","Cumulative GM Percentage":"0.000106730367844277"},{"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":"28091.3","Gross Margin on Sales":"-175.740000000004","Cost-of-Goods Sold":"-6126.54","Average Price":"34.6806172839506","Last Price":"34.48","Cumulative COGS":"-11443.25","Cumulative Gross Margin":"-485.290000000004","GM Percentage":"-0.0295321637426908","Cumulative GM Percentage":"-0.044286527784369"},{"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":"22387.28","Gross Margin on Sales":"43.7399999999998","Cost-of-Goods Sold":"-5704.02","Average Price":"34.5482716049383","Last Price":"34.48","Cumulative COGS":"-17147.27","Cumulative Gross Margin":"-441.550000000004","GM Percentage":"0.00760992108229985","Cumulative GM Percentage":"-0.0264310667244515"},{"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":"10375.66","Gross Margin on Sales":"234.01","Cost-of-Goods Sold":"-12011.62","Average Price":"34.4706312292359","Last Price":"34.48","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"0.0191096742266425","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"25283.16","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.89163538874","Last Price":"33.5","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"34493.08","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.8831827111984","Last Price":"33.86","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"38141.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.0243889384478","Last Price":"35.42","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"49604.94","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.2339130434783","Last Price":"34.95","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"39574.08","Gross Margin on Sales":"354.93","Cost-of-Goods Sold":"-10030.86","Average Price":"34.1745077720207","Last Price":"34.95","Cumulative COGS":"-39189.75","Cumulative Gross Margin":"147.389999999997","GM Percentage":"0.0341745789198511","Cumulative GM Percentage":"0.00374684077185064"},{"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":"29681.78","Gross Margin on Sales":"-301.850000000002","Cost-of-Goods Sold":"-9892.3","Average Price":"34.3937195828505","Last Price":"34.95","Cumulative COGS":"-49082.05","Cumulative Gross Margin":"-154.460000000005","GM Percentage":"-0.0314740184245788","Cumulative GM Percentage":"-0.00315691003787445"},{"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":"26633.28","Gross Margin on Sales":"-34.5799999999999","Cost-of-Goods Sold":"-3048.5","Average Price":"34.4990673575129","Last Price":"34.95","Cumulative COGS":"-52130.55","Cumulative Gross Margin":"-189.040000000005","GM Percentage":"-0.0114734299516908","Cumulative GM Percentage":"-0.00363947832860472"},{"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":"25092.28","Gross Margin on Sales":"52.9000000000001","Cost-of-Goods Sold":"-1541","Average Price":"34.5623691460055","Last Price":"34.95","Cumulative COGS":"-53671.55","Cumulative Gross Margin":"-136.140000000005","GM Percentage":"0.0331890331890332","Cumulative GM Percentage":"-0.00254298977069579"},{"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":"16771","Gross Margin on Sales":"438.780000000001","Cost-of-Goods Sold":"-8321.28","Average Price":"34.9395833333333","Last Price":"34.95","Cumulative COGS":"-61992.83","Cumulative Gross Margin":"302.639999999995","GM Percentage":"0.0500886980226164","Cumulative GM Percentage":"0.00485813815996565"},{"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":"5592","Gross Margin on Sales":"-247.799999999999","Cost-of-Goods Sold":"-11179","Average Price":"34.95","Last Price":"34.95","Cumulative COGS":"-73171.83","Cumulative Gross Margin":"54.8399999999961","GM Percentage":"-0.0226690573770491","Cumulative GM Percentage":"0.000748907467729941"},{"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":"2376.6","Gross Margin on Sales":"-211.6","Cost-of-Goods Sold":"-3215.4","Average Price":"34.95","Last Price":"34.95","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"-0.0704441041347626","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"8708.42","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1506666666667","Last Price":"33.86","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"11567.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.023","Last Price":"33.64","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"28342.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7414523809524","Last Price":"33.55","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"30818.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7918640350877","Last Price":"34.38","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"43410.42","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7037422360248","Last Price":"33.49","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"57476.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1308432304038","Last Price":"35.52","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"54761.14","Gross Margin on Sales":"50.6800000000103","Cost-of-Goods Sold":"-2715.19999999999","Average Price":"34.0978455790785","Last Price":"35.52","Cumulative COGS":"-79102.43","Cumulative Gross Margin":"-106.079999999994","GM Percentage":"0.0183232822826769","Cumulative GM Percentage":"-0.00134284685305072"},{"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":"16263.28","Gross Margin on Sales":"262.480000000002","Cost-of-Goods Sold":"-4543.22","Average Price":"23.2001141226819","Last Price":"24.04","Cumulative COGS":"-4543.22","Cumulative Gross Margin":"262.480000000002","GM Percentage":"0.0546184738955828","Cumulative GM Percentage":"0.0546184738955828"},{"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":"15792.48","Gross Margin on Sales":"0.99999999999892","Cost-of-Goods Sold":"-470.800000000001","Average Price":"23.1901321585903","Last Price":"24.04","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"0.00211954217888707","Cumulative GM Percentage":"0.0499251539554716"},{"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":"22620.73","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6618514644351","Last Price":"24.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"28513.48","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7810508757298","Last Price":"24.25","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"35341.73","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.976750339213","Last Price":"24.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"41665.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7953398058252","Last Price":"22.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"44950.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7454305335446","Last Price":"23.13","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"46238.75","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7365246406571","Last Price":"23.43","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"48676.36","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8026210268949","Last Price":"25.13","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"56100.91","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7715720338983","Last Price":"23.57","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"66911.96","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.668892819243","Last Price":"23.15","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"69681.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6929683781027","Last Price":"24.29","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"82695.62","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7222088353414","Last Price":"23.88","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"89639.78","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.701686938128","Last Price":"23.46","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"100039.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8472276519666","Last Price":"25.18","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"104675.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8060086422561","Last Price":"22.95","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"98272.14","Gross Margin on Sales":"-24.4799999999905","Cost-of-Goods Sold":"-6402.87999999999","Average Price":"23.8235490909091","Last Price":"22.95","Cumulative COGS":"-11416.9","Cumulative Gross Margin":"239.000000000011","GM Percentage":"-0.00383795309168294","Cumulative GM Percentage":"0.0205046371365584"},{"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":"91910.68","Gross Margin on Sales":"566.309999999994","Cost-of-Goods Sold":"-6361.46000000001","Average Price":"23.8853118503119","Last Price":"22.95","Cumulative COGS":"-17778.36","Cumulative Gross Margin":"805.310000000005","GM Percentage":"0.0817449193607747","Cumulative GM Percentage":"0.0433342821950672"},{"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":"87939","Gross Margin on Sales":"16.5200000000068","Cost-of-Goods Sold":"-3971.67999999999","Average Price":"23.9094616639478","Last Price":"22.95","Cumulative COGS":"-21750.04","Cumulative Gross Margin":"821.830000000012","GM Percentage":"0.00414221954766732","Cumulative GM Percentage":"0.0364094778146433"},{"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":"85753.96","Gross Margin on Sales":"-16.720000000008","Cost-of-Goods Sold":"-2185.04000000001","Average Price":"23.8868969359331","Last Price":"22.95","Cumulative COGS":"-23935.08","Cumulative Gross Margin":"805.110000000004","GM Percentage":"-0.00771103896104264","Cumulative GM Percentage":"0.0325425956712541"},{"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":"81714.79","Gross Margin on Sales":"-184.219999999998","Cost-of-Goods Sold":"-4039.17","Average Price":"23.8444091041727","Last Price":"22.95","Cumulative COGS":"-27974.25","Cumulative Gross Margin":"620.890000000005","GM Percentage":"-0.0477879090519977","Cumulative GM Percentage":"0.0217131302731865"},{"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":"80235.54","Gross Margin on Sales":"-62.22","Cost-of-Goods Sold":"-1479.25","Average Price":"23.8370588235294","Last Price":"22.95","Cumulative COGS":"-29453.5","Cumulative Gross Margin":"558.670000000005","GM Percentage":"-0.043908738699957","Cumulative GM Percentage":"0.0186147819367945"},{"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":"79920.29","Gross Margin on Sales":"-3.63999999999999","Cost-of-Goods Sold":"-315.25","Average Price":"23.835457798986","Last Price":"22.95","Cumulative COGS":"-29768.75","Cumulative Gross Margin":"555.030000000005","GM Percentage":"-0.0116812682519816","Cumulative GM Percentage":"0.0183034568909287"},{"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":"76355.54","Gross Margin on Sales":"-64.6799999999998","Cost-of-Goods Sold":"-3564.75","Average Price":"23.8164504054897","Last Price":"22.95","Cumulative COGS":"-33333.5","Cumulative Gross Margin":"490.350000000005","GM Percentage":"-0.0184796304073918","Cumulative GM Percentage":"0.0144971669398961"},{"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":"78618.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8383080654942","Last Price":"24.6","Cumulative COGS":"-33333.5","Cumulative Gross Margin":"490.350000000005","GM Percentage":"NULL","Cumulative GM Percentage":"0.0144971669398961"},{"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":"72465.54","Gross Margin on Sales":"-57.3599999999969","Cost-of-Goods Sold":"-6153.2","Average Price":"23.759193442623","Last Price":"24.6","Cumulative COGS":"-39486.7","Cumulative Gross Margin":"432.990000000008","GM Percentage":"-0.00940969579253999","Cumulative GM Percentage":"0.010846527114815"},{"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":"66688.04","Gross Margin on Sales":"2.5","Cost-of-Goods Sold":"-5777.5","Average Price":"23.8171571428571","Last Price":"24.6","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"0.000432525951557093","Cumulative GM Percentage":"0.00952938630437117"},{"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":"80491.4","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7018256772674","Last Price":"23.16","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"89075.09","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7217283621838","Last Price":"23.91","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"99730.21","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8646111509931","Last Price":"25.13","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"96209.92","Gross Margin on Sales":"199.140000000006","Cost-of-Goods Sold":"-3520.28999999999","Average Price":"23.8971485345256","Last Price":"25.13","Cumulative COGS":"-48784.49","Cumulative Gross Margin":"634.630000000015","GM Percentage":"0.0535404618449618","Cumulative GM Percentage":"0.0128417907886667"},{"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":"90243.38","Gross Margin on Sales":"161.539999999992","Cost-of-Goods Sold":"-5966.54000000001","Average Price":"23.8865484383272","Last Price":"25.13","Cumulative COGS":"-54751.03","Cumulative Gross Margin":"796.170000000006","GM Percentage":"0.0263606219239944","Cumulative GM Percentage":"0.0143332157156437"},{"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":"82027.48","Gross Margin on Sales":"-39.8999999999942","Cost-of-Goods Sold":"-8215.89999999999","Average Price":"23.9286697782964","Last Price":"25.13","Cumulative COGS":"-62966.93","Cumulative Gross Margin":"756.270000000012","GM Percentage":"-0.00488013698630066","Cumulative GM Percentage":"0.0118680480578504"},{"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":"74480.58","Gross Margin on Sales":"29.3399999999911","Cost-of-Goods Sold":"-7546.90000000001","Average Price":"24.010502901354","Last Price":"25.13","Cumulative COGS":"-70513.83","Cumulative Gross Margin":"785.610000000003","GM Percentage":"0.0038726333907045","Cumulative GM Percentage":"0.0110184596120251"},{"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":"67839.73","Gross Margin on Sales":"-196.809999999991","Cost-of-Goods Sold":"-6640.84999999999","Average Price":"24.0225672804533","Last Price":"25.13","Cumulative COGS":"-77154.68","Cumulative Gross Margin":"588.800000000012","GM Percentage":"-0.0305413994947256","Cumulative GM Percentage":"0.0075736254667274"},{"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":"75544.63","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0664638419879","Last Price":"24.46","Cumulative COGS":"-77154.68","Cumulative Gross Margin":"588.800000000012","GM Percentage":"NULL","Cumulative GM Percentage":"0.0075736254667274"},{"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":"66565.75","Gross Margin on Sales":"466.239999999996","Cost-of-Goods Sold":"-8978.88","Average Price":"24.0918385812523","Last Price":"24.46","Cumulative COGS":"-86133.56","Cumulative Gross Margin":"1055.04000000001","GM Percentage":"0.0493630573248404","Cumulative GM Percentage":"0.0121006645364188"},{"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":"61939.87","Gross Margin on Sales":"-121.800000000005","Cost-of-Goods Sold":"-4625.88","Average Price":"24.1292832099727","Last Price":"24.46","Cumulative COGS":"-90759.44","Cumulative Gross Margin":"933.240000000003","GM Percentage":"-0.0270421484520712","Cumulative GM Percentage":"0.0101779116937143"},{"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":"68323.93","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1598055162659","Last Price":"24.46","Cumulative COGS":"-90759.44","Cumulative Gross Margin":"933.240000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0101779116937143"},{"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":"62238.91","Gross Margin on Sales":"103.360000000011","Cost-of-Goods Sold":"-6085.01999999999","Average Price":"24.1704504854369","Last Price":"24.46","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"0.0167022710305461","Cumulative GM Percentage":"0.0105904043131533"},{"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":"70299.87","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1829618163055","Last Price":"24.28","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"80088.79","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1887012987013","Last Price":"24.23","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"93048.99","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1122026431718","Last Price":"23.65","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"103927.29","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0683858267717","Last Price":"23.7","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"98689.85","Gross Margin on Sales":"-170.560000000017","Cost-of-Goods Sold":"-5237.44000000002","Average Price":"24.0121289537713","Last Price":"23.7","Cumulative COGS":"-102081.9","Cumulative Gross Margin":"866.039999999997","GM Percentage":"-0.0336617405582956","Cumulative GM Percentage":"0.00841240728080618"},{"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":"99714.23","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0159513487476","Last Price":"24.39","Cumulative COGS":"-102081.9","Cumulative Gross Margin":"866.039999999997","GM Percentage":"NULL","Cumulative GM Percentage":"0.00841240728080618"}]}
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 FIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #fifo
FROM wct.FIFOtvf('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,
f.[QTY] as [GBP Position],
f.[EB] as [USD Position],
f.[GM] as [P/L],
f.[COGS] as [Cost-of-Goods Sold],
f.[UP] as [Average Price],
f.[LP] as [Last Price],
f.[COGSC] as [Cumulative COGS],
f.[GMC] as [Cumulative P/L],
f.[GMP] as [GM Percentage],
f.[CGMP] as [Cumulative GM Percentage]
FROM #fx c
INNER JOIN #FIFO f
ON c.trn = f.[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":"3246000","P/L":"-20000","Cost-of-Goods Sold":"-8110000","Average Price":"1.623","Last Price":"1.623","Cumulative COGS":"-11370000","Cumulative P/L":"-28000","GM Percentage":"-0.00247218788627936","Cumulative GM Percentage":"-0.00246870040557221"},{"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":"-42000","Cost-of-Goods Sold":"-3246000","Average Price":"1.602","Last Price":"1.602","Cumulative COGS":"-14616000","Cumulative P/L":"-70000","GM Percentage":"-0.0131086142322097","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 FIFOtvf 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 FIFO Values and store in temp table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #fifo
FROM wct.FIFOtvf('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,
f.[QTY] as [Inventory-On-Hand],
f.[EB] as [Inventory Cost],
f.[GM] as [Gross Margin on Sales],
f.[COGS] as [Cost-of-Goods Sold],
f.[UP] as [Average Price],
f.[LP] as [Last Price],
f.[COGSC] as [Cumulative COGS],
f.[GMC] as [Cumulative Gross Margin],
f.[GMP] as [GM Percentage],
f.[CGMP] as [Cumulative GM Percentage]
FROM #inv i
INNER JOIN #FIFO f
ON i.ID = f.[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":"3077.75","Gross Margin on Sales":"61.23","Cost-of-Goods Sold":"-2006.46","Average Price":"12.9317226890756","Last Price":"13.01","Cumulative COGS":"-2006.46","Cumulative Gross Margin":"61.23","GM Percentage":"0.0296127562642369","Cumulative GM Percentage":"0.0296127562642369"},{"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":"2272.61","Gross Margin on Sales":"-10.7100000000004","Cost-of-Goods Sold":"-805.14","Average Price":"12.9863428571429","Last Price":"13.01","Cumulative COGS":"-2811.6","Cumulative Gross Margin":"50.5199999999996","GM Percentage":"-0.0134813639968284","Cumulative GM Percentage":"0.0176512515198523"},{"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":"8467.55","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2720219435737","Last Price":"13.38","Cumulative COGS":"-2811.6","Cumulative Gross Margin":"50.5199999999996","GM Percentage":"NULL","Cumulative GM Percentage":"0.0176512515198523"},{"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":"7274.77","Gross Margin on Sales":"62.1000000000004","Cost-of-Goods Sold":"-1192.78","Average Price":"13.3237545787546","Last Price":"13.38","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"0.0494868035190619","Cumulative GM Percentage":"0.027354870051008"},{"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":"11142.81","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2023815165877","Last Price":"12.98","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"NULL","Cumulative GM Percentage":"0.027354870051008"},{"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":"14193.09","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2274836905871","Last Price":"13.32","Cumulative COGS":"-4004.38","Cumulative Gross Margin":"112.62","GM Percentage":"NULL","Cumulative GM Percentage":"0.027354870051008"},{"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":"11668.22","Gross Margin on Sales":"51.7199999999993","Cost-of-Goods Sold":"-2524.87","Average Price":"13.2292743764172","Last Price":"13.32","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"0.0200730422768075","Cumulative GM Percentage":"0.0245518473644187"},{"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":"14712.24","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1359285714286","Last Price":"12.79","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"18654.78","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1556981664316","Last Price":"13.23","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"20347.38","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1443023255814","Last Price":"13.02","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"24394.47","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1082590005373","Last Price":"12.93","Cumulative COGS":"-6529.25","Cumulative Gross Margin":"164.339999999999","GM Percentage":"NULL","Cumulative GM Percentage":"0.0245518473644187"},{"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":"20032.59","Gross Margin on Sales":"-211.899999999998","Cost-of-Goods Sold":"-4361.88","Average Price":"13.0505472312704","Last Price":"12.93","Cumulative COGS":"-10891.13","Cumulative Gross Margin":"-47.5599999999985","GM Percentage":"-0.0510604870384912","Cumulative GM Percentage":"-0.00438600940465165"},{"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":"17074.53","Gross Margin on Sales":"99.6299999999987","Cost-of-Goods Sold":"-2958.06","Average Price":"13.0539220183486","Last Price":"12.93","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"0.0325834208176757","Cumulative GM Percentage":"0.0037457036268655"},{"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":"25250.88","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2411536444677","Last Price":"13.65","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0037457036268655"},{"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":"26321.33","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2534390735146","Last Price":"13.55","Cumulative COGS":"-13849.19","Cumulative Gross Margin":"52.0700000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0037457036268655"},{"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":"21244.02","Gross Margin on Sales":"191.590000000006","Cost-of-Goods Sold":"-5077.30999999999","Average Price":"13.2775125","Last Price":"13.55","Cumulative COGS":"-18926.5","Cumulative Gross Margin":"243.660000000006","GM Percentage":"0.0363624285904089","Cumulative GM Percentage":"0.0127103790474365"},{"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":"27462.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.1397703349282","Last Price":"12.69","Cumulative COGS":"-18926.5","Cumulative Gross Margin":"243.660000000006","GM Percentage":"NULL","Cumulative GM Percentage":"0.0127103790474365"},{"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":"24869.3","Gross Margin on Sales":"21.0599999999968","Cost-of-Goods Sold":"-2592.82","Average Price":"13.1722987288136","Last Price":"12.69","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"0.00805698807902305","Cumulative GM Percentage":"0.0121520158795156"},{"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":"28223.33","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2069864295742","Last Price":"13.47","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"30721.65","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2192986230637","Last Price":"13.36","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"31064.01","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"13.2131050616759","Last Price":"12.68","Cumulative COGS":"-21519.32","Cumulative Gross Margin":"264.720000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0121520158795156"},{"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":"25980.12","Gross Margin on Sales":"-297.49","Cost-of-Goods Sold":"-5083.89","Average Price":"13.2214351145038","Last Price":"12.68","Cumulative COGS":"-26603.21","Cumulative Gross Margin":"-32.7699999999971","GM Percentage":"-0.0621531840213939","Cumulative GM Percentage":"-0.00123332545490391"},{"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":"24103.38","Gross Margin on Sales":"35.810000000002","Cost-of-Goods Sold":"-1876.74","Average Price":"13.2436153846154","Last Price":"12.68","Cumulative COGS":"-28479.95","Cumulative Gross Margin":"3.04000000000485","GM Percentage":"0.0187236934982102","Cumulative GM Percentage":"0.000106730367844277"},{"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":"28091.3","Gross Margin on Sales":"-175.740000000004","Cost-of-Goods Sold":"-6126.54","Average Price":"34.6806172839506","Last Price":"34.48","Cumulative COGS":"-11443.25","Cumulative Gross Margin":"-485.290000000004","GM Percentage":"-0.0295321637426908","Cumulative GM Percentage":"-0.044286527784369"},{"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":"22387.28","Gross Margin on Sales":"43.7399999999998","Cost-of-Goods Sold":"-5704.02","Average Price":"34.5482716049383","Last Price":"34.48","Cumulative COGS":"-17147.27","Cumulative Gross Margin":"-441.550000000004","GM Percentage":"0.00760992108229985","Cumulative GM Percentage":"-0.0264310667244515"},{"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":"10375.66","Gross Margin on Sales":"234.01","Cost-of-Goods Sold":"-12011.62","Average Price":"34.4706312292359","Last Price":"34.48","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"0.0191096742266425","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"25283.16","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.89163538874","Last Price":"33.5","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"34493.08","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.8831827111984","Last Price":"33.86","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"38141.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.0243889384478","Last Price":"35.42","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"49604.94","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.2339130434783","Last Price":"34.95","Cumulative COGS":"-29158.89","Cumulative Gross Margin":"-207.540000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.00716857763109505"},{"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":"39574.08","Gross Margin on Sales":"354.93","Cost-of-Goods Sold":"-10030.86","Average Price":"34.1745077720207","Last Price":"34.95","Cumulative COGS":"-39189.75","Cumulative Gross Margin":"147.389999999997","GM Percentage":"0.0341745789198511","Cumulative GM Percentage":"0.00374684077185064"},{"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":"29681.78","Gross Margin on Sales":"-301.850000000002","Cost-of-Goods Sold":"-9892.3","Average Price":"34.3937195828505","Last Price":"34.95","Cumulative COGS":"-49082.05","Cumulative Gross Margin":"-154.460000000005","GM Percentage":"-0.0314740184245788","Cumulative GM Percentage":"-0.00315691003787445"},{"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":"26633.28","Gross Margin on Sales":"-34.5799999999999","Cost-of-Goods Sold":"-3048.5","Average Price":"34.4990673575129","Last Price":"34.95","Cumulative COGS":"-52130.55","Cumulative Gross Margin":"-189.040000000005","GM Percentage":"-0.0114734299516908","Cumulative GM Percentage":"-0.00363947832860472"},{"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":"25092.28","Gross Margin on Sales":"52.9000000000001","Cost-of-Goods Sold":"-1541","Average Price":"34.5623691460055","Last Price":"34.95","Cumulative COGS":"-53671.55","Cumulative Gross Margin":"-136.140000000005","GM Percentage":"0.0331890331890332","Cumulative GM Percentage":"-0.00254298977069579"},{"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":"16771","Gross Margin on Sales":"438.780000000001","Cost-of-Goods Sold":"-8321.28","Average Price":"34.9395833333333","Last Price":"34.95","Cumulative COGS":"-61992.83","Cumulative Gross Margin":"302.639999999995","GM Percentage":"0.0500886980226164","Cumulative GM Percentage":"0.00485813815996565"},{"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":"5592","Gross Margin on Sales":"-247.799999999999","Cost-of-Goods Sold":"-11179","Average Price":"34.95","Last Price":"34.95","Cumulative COGS":"-73171.83","Cumulative Gross Margin":"54.8399999999961","GM Percentage":"-0.0226690573770491","Cumulative GM Percentage":"0.000748907467729941"},{"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":"2376.6","Gross Margin on Sales":"-211.6","Cost-of-Goods Sold":"-3215.4","Average Price":"34.95","Last Price":"34.95","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"-0.0704441041347626","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"8708.42","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1506666666667","Last Price":"33.86","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"11567.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.023","Last Price":"33.64","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"28342.82","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7414523809524","Last Price":"33.55","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"30818.18","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7918640350877","Last Price":"34.38","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"43410.42","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"33.7037422360248","Last Price":"33.49","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"57476.34","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"34.1308432304038","Last Price":"35.52","Cumulative COGS":"-76387.23","Cumulative Gross Margin":"-156.760000000004","GM Percentage":"NULL","Cumulative GM Percentage":"-0.0020563955594135"},{"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":"54761.14","Gross Margin on Sales":"50.6800000000103","Cost-of-Goods Sold":"-2715.19999999999","Average Price":"34.0978455790785","Last Price":"35.52","Cumulative COGS":"-79102.43","Cumulative Gross Margin":"-106.079999999994","GM Percentage":"0.0183232822826769","Cumulative GM Percentage":"-0.00134284685305072"},{"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":"16263.28","Gross Margin on Sales":"262.480000000002","Cost-of-Goods Sold":"-4543.22","Average Price":"23.2001141226819","Last Price":"24.04","Cumulative COGS":"-4543.22","Cumulative Gross Margin":"262.480000000002","GM Percentage":"0.0546184738955828","Cumulative GM Percentage":"0.0546184738955828"},{"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":"15792.48","Gross Margin on Sales":"0.99999999999892","Cost-of-Goods Sold":"-470.800000000001","Average Price":"23.1901321585903","Last Price":"24.04","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"0.00211954217888707","Cumulative GM Percentage":"0.0499251539554716"},{"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":"22620.73","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6618514644351","Last Price":"24.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"28513.48","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7810508757298","Last Price":"24.25","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"35341.73","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.976750339213","Last Price":"24.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"41665.64","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7953398058252","Last Price":"22.83","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"44950.1","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7454305335446","Last Price":"23.13","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"46238.75","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7365246406571","Last Price":"23.43","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"48676.36","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8026210268949","Last Price":"25.13","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"56100.91","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7715720338983","Last Price":"23.57","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"66911.96","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.668892819243","Last Price":"23.15","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"69681.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.6929683781027","Last Price":"24.29","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"82695.62","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7222088353414","Last Price":"23.88","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"89639.78","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.701686938128","Last Price":"23.46","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"100039.12","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8472276519666","Last Price":"25.18","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"104675.02","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8060086422561","Last Price":"22.95","Cumulative COGS":"-5014.02","Cumulative Gross Margin":"263.480000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0499251539554716"},{"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":"98272.14","Gross Margin on Sales":"-24.4799999999905","Cost-of-Goods Sold":"-6402.87999999999","Average Price":"23.8235490909091","Last Price":"22.95","Cumulative COGS":"-11416.9","Cumulative Gross Margin":"239.000000000011","GM Percentage":"-0.00383795309168294","Cumulative GM Percentage":"0.0205046371365584"},{"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":"91910.68","Gross Margin on Sales":"566.309999999994","Cost-of-Goods Sold":"-6361.46000000001","Average Price":"23.8853118503119","Last Price":"22.95","Cumulative COGS":"-17778.36","Cumulative Gross Margin":"805.310000000005","GM Percentage":"0.0817449193607747","Cumulative GM Percentage":"0.0433342821950672"},{"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":"87939","Gross Margin on Sales":"16.5200000000068","Cost-of-Goods Sold":"-3971.67999999999","Average Price":"23.9094616639478","Last Price":"22.95","Cumulative COGS":"-21750.04","Cumulative Gross Margin":"821.830000000012","GM Percentage":"0.00414221954766732","Cumulative GM Percentage":"0.0364094778146433"},{"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":"85753.96","Gross Margin on Sales":"-16.720000000008","Cost-of-Goods Sold":"-2185.04000000001","Average Price":"23.8868969359331","Last Price":"22.95","Cumulative COGS":"-23935.08","Cumulative Gross Margin":"805.110000000004","GM Percentage":"-0.00771103896104264","Cumulative GM Percentage":"0.0325425956712541"},{"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":"81714.79","Gross Margin on Sales":"-184.219999999998","Cost-of-Goods Sold":"-4039.17","Average Price":"23.8444091041727","Last Price":"22.95","Cumulative COGS":"-27974.25","Cumulative Gross Margin":"620.890000000005","GM Percentage":"-0.0477879090519977","Cumulative GM Percentage":"0.0217131302731865"},{"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":"80235.54","Gross Margin on Sales":"-62.22","Cost-of-Goods Sold":"-1479.25","Average Price":"23.8370588235294","Last Price":"22.95","Cumulative COGS":"-29453.5","Cumulative Gross Margin":"558.670000000005","GM Percentage":"-0.043908738699957","Cumulative GM Percentage":"0.0186147819367945"},{"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":"79920.29","Gross Margin on Sales":"-3.63999999999999","Cost-of-Goods Sold":"-315.25","Average Price":"23.835457798986","Last Price":"22.95","Cumulative COGS":"-29768.75","Cumulative Gross Margin":"555.030000000005","GM Percentage":"-0.0116812682519816","Cumulative GM Percentage":"0.0183034568909287"},{"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":"76355.54","Gross Margin on Sales":"-64.6799999999998","Cost-of-Goods Sold":"-3564.75","Average Price":"23.8164504054897","Last Price":"22.95","Cumulative COGS":"-33333.5","Cumulative Gross Margin":"490.350000000005","GM Percentage":"-0.0184796304073918","Cumulative GM Percentage":"0.0144971669398961"},{"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":"78618.74","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8383080654942","Last Price":"24.6","Cumulative COGS":"-33333.5","Cumulative Gross Margin":"490.350000000005","GM Percentage":"NULL","Cumulative GM Percentage":"0.0144971669398961"},{"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":"72465.54","Gross Margin on Sales":"-57.3599999999969","Cost-of-Goods Sold":"-6153.2","Average Price":"23.759193442623","Last Price":"24.6","Cumulative COGS":"-39486.7","Cumulative Gross Margin":"432.990000000008","GM Percentage":"-0.00940969579253999","Cumulative GM Percentage":"0.010846527114815"},{"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":"66688.04","Gross Margin on Sales":"2.5","Cost-of-Goods Sold":"-5777.5","Average Price":"23.8171571428571","Last Price":"24.6","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"0.000432525951557093","Cumulative GM Percentage":"0.00952938630437117"},{"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":"80491.4","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7018256772674","Last Price":"23.16","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"89075.09","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.7217283621838","Last Price":"23.91","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"99730.21","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"23.8646111509931","Last Price":"25.13","Cumulative COGS":"-45264.2","Cumulative Gross Margin":"435.490000000008","GM Percentage":"NULL","Cumulative GM Percentage":"0.00952938630437117"},{"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":"96209.92","Gross Margin on Sales":"199.140000000006","Cost-of-Goods Sold":"-3520.28999999999","Average Price":"23.8971485345256","Last Price":"25.13","Cumulative COGS":"-48784.49","Cumulative Gross Margin":"634.630000000015","GM Percentage":"0.0535404618449618","Cumulative GM Percentage":"0.0128417907886667"},{"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":"90243.38","Gross Margin on Sales":"161.539999999992","Cost-of-Goods Sold":"-5966.54000000001","Average Price":"23.8865484383272","Last Price":"25.13","Cumulative COGS":"-54751.03","Cumulative Gross Margin":"796.170000000006","GM Percentage":"0.0263606219239944","Cumulative GM Percentage":"0.0143332157156437"},{"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":"82027.48","Gross Margin on Sales":"-39.8999999999942","Cost-of-Goods Sold":"-8215.89999999999","Average Price":"23.9286697782964","Last Price":"25.13","Cumulative COGS":"-62966.93","Cumulative Gross Margin":"756.270000000012","GM Percentage":"-0.00488013698630066","Cumulative GM Percentage":"0.0118680480578504"},{"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":"74480.58","Gross Margin on Sales":"29.3399999999911","Cost-of-Goods Sold":"-7546.90000000001","Average Price":"24.010502901354","Last Price":"25.13","Cumulative COGS":"-70513.83","Cumulative Gross Margin":"785.610000000003","GM Percentage":"0.0038726333907045","Cumulative GM Percentage":"0.0110184596120251"},{"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":"67839.73","Gross Margin on Sales":"-196.809999999991","Cost-of-Goods Sold":"-6640.84999999999","Average Price":"24.0225672804533","Last Price":"25.13","Cumulative COGS":"-77154.68","Cumulative Gross Margin":"588.800000000012","GM Percentage":"-0.0305413994947256","Cumulative GM Percentage":"0.0075736254667274"},{"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":"75544.63","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0664638419879","Last Price":"24.46","Cumulative COGS":"-77154.68","Cumulative Gross Margin":"588.800000000012","GM Percentage":"NULL","Cumulative GM Percentage":"0.0075736254667274"},{"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":"66565.75","Gross Margin on Sales":"466.239999999996","Cost-of-Goods Sold":"-8978.88","Average Price":"24.0918385812523","Last Price":"24.46","Cumulative COGS":"-86133.56","Cumulative Gross Margin":"1055.04000000001","GM Percentage":"0.0493630573248404","Cumulative GM Percentage":"0.0121006645364188"},{"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":"61939.87","Gross Margin on Sales":"-121.800000000005","Cost-of-Goods Sold":"-4625.88","Average Price":"24.1292832099727","Last Price":"24.46","Cumulative COGS":"-90759.44","Cumulative Gross Margin":"933.240000000003","GM Percentage":"-0.0270421484520712","Cumulative GM Percentage":"0.0101779116937143"},{"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":"68323.93","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1598055162659","Last Price":"24.46","Cumulative COGS":"-90759.44","Cumulative Gross Margin":"933.240000000003","GM Percentage":"NULL","Cumulative GM Percentage":"0.0101779116937143"},{"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":"62238.91","Gross Margin on Sales":"103.360000000011","Cost-of-Goods Sold":"-6085.01999999999","Average Price":"24.1704504854369","Last Price":"24.46","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"0.0167022710305461","Cumulative GM Percentage":"0.0105904043131533"},{"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":"70299.87","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1829618163055","Last Price":"24.28","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"80088.79","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1887012987013","Last Price":"24.23","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"93048.99","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.1122026431718","Last Price":"23.65","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"103927.29","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0683858267717","Last Price":"23.7","Cumulative COGS":"-96844.46","Cumulative Gross Margin":"1036.60000000001","GM Percentage":"NULL","Cumulative GM Percentage":"0.0105904043131533"},{"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":"98689.85","Gross Margin on Sales":"-170.560000000017","Cost-of-Goods Sold":"-5237.44000000002","Average Price":"24.0121289537713","Last Price":"23.7","Cumulative COGS":"-102081.9","Cumulative Gross Margin":"866.039999999997","GM Percentage":"-0.0336617405582956","Cumulative GM Percentage":"0.00841240728080618"},{"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":"99714.23","Gross Margin on Sales":"0","Cost-of-Goods Sold":"0","Average Price":"24.0159513487476","Last Price":"24.39","Cumulative COGS":"-102081.9","Cumulative Gross Margin":"866.039999999997","GM Percentage":"NULL","Cumulative GM Percentage":"0.00841240728080618"}]}
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 FIFO 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 #fifo table
SELECT CAST([ID] as Int) as ID,
[QTY],
[EB],
[GM],
[COGS],
[UP],
[LP],
[COGSC],
[GMC],
[GMP],
[CGMP]
INTO #fifo
FROM wct.FIFOtvf('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],
f.[QTY] as [Inventory-On-Hand],
f.[EB] as [Inventory Cost],
f.[GM] as [Gross Margin on Sales],
f.[COGS] as [Cost-of-Goods Sold],
f.[UP] as [Average Price],
f.[LP] as [Last Price],
f.[COGSC] as [Cumulative COGS],
f.[GMC] as [Cumulative Gross Margin],
f.[GMP] as [GM Percentage],
f.[CGMP] as [Cumulative GM Percentage]
FROM #p2
INNER JOIN #FIFO f
ON #p2.ID = f.[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.18000000000001","Cost-of-Goods Sold":"-2.66999999999999","Average Price":"0.89","Last Price":"0.89","Cumulative COGS":"-9.79","Cumulative Gross Margin":"22.66","GM Percentage":"0.698305084745763","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":"80.64","Gross Margin on Sales":"12.36","Cost-of-Goods Sold":"-5.34","Average Price":"1.06105263157895","Last Price":"1.15","Cumulative COGS":"-21.36","Cumulative Gross Margin":"49.44","GM Percentage":"0.698305084745762","Cumulative GM Percentage":"0.698305084745763"},{"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":"78.86","Gross Margin on Sales":"4.12","Cost-of-Goods Sold":"-1.78","Average Price":"1.06567567567568","Last Price":"1.15","Cumulative COGS":"-23.14","Cumulative Gross Margin":"53.56","GM Percentage":"0.698305084745763","Cumulative GM Percentage":"0.698305084745763"}]}
See Also
FIFO - Calculate FIFO (first in, first out) values in an ordered resultant table.
LIFO - Calculate LIFO (last in, first out) values in an ordered resultant table.
WAC - Calculate running weighted average cost in an ordered resultant table.
FIFOEnd - Calculate the ending FIFO balances in an ordered resultant table.
LIFOend - Calculate the ending LIFO balances in an ordered resultant table.
LIFOtvf - Calculate the running LIFO balances in an ordered resultant table.
WACtvf - Calculate running weighted-average cost values in an ordered resultant table.