Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Historical Sales Inventory value by customer

$
0
0

The below query will give you the sold inventory values with including quantity, sold value, sold price and profit by customer.

SELECT Vendor
,ITEMNMBR
,QTY
,[Sold Value]
,[Sold Price]
,[Sold Price] – [Sold Value] AS Profit
FROM (
SELECT CUSTNMBR AS Vendor
,ITEMNMBR
,(
SELECT SUM(- TRXQTY)
FROM IV30300
WHERE ITEMNMBR = A.ITEMNMBR
AND DOCTYPE = 6
AND CUSTNMBR = A.CUSTNMBR
) AS QTY
,(
SELECT SUM(EXTDCOST)
FROM IV30300
WHERE ITEMNMBR = A.ITEMNMBR
AND DOCTYPE = 6
AND CUSTNMBR = A.CUSTNMBR
) AS [Sold Value]
,(
(
SELECT SUM(- AA.TRXQTY * BB.UNITPRCE)
FROM IV30300 AA
INNER JOIN SOP30300 BB ON BB.SOPTYPE = 3
AND AA.DOCNUMBR = BB.SOPNUMBE
AND AA.LNSEQNBR = BB.LNITMSEQ
WHERE AA.ITEMNMBR = A.ITEMNMBR
AND AA.DOCTYPE = 6
AND CUSTNMBR = A.CUSTNMBR
GROUP BY AA.ITEMNMBR
)
) AS [Sold Price]
FROM IV30300 A
WHERE A.CUSTNMBR <> ”
AND DOCTYPE = 6
GROUP BY A.CUSTNMBR
,A.ITEMNMBR
) SalesByCustomer

Hope this helps!!!



Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>