web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

On hand inventory based on date

(0) ShareShare
ReportReport
Posted on by

I need to get on hand inventory for the beginning and ending of last year for each item. This can be done be an TSQL script, x++ , SSRS report doesn't matter. Does anyone know how to get this information in AX 2012

*This post is locked for comments

I have the same question (0)
  • Fredrik Sætre Profile Picture
    12,644 on at

    InventTrans

  • Community Member Profile Picture
    on at

    Thanks for the reply. Would I use the DatePhysical date for the date range and sum by the physical qty?

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Well by just querying on inventTrans(based on daterange), you may get only relative value but not absolute value of on hand for a given item.

    Initially we need to get the onHand value on end of last year(from today).

    Use InventOnHand query to get the current on hand for every item variant, by considering only the

    items they were created before/in last year(createdDateTime on InventTable is before/in last year).

    Loop through the inventrans table joined with inventDim, group by item

    -- get the sum of positive quantity from InventTrans by considering datePhysical as daterange(between today and end of last year)

    -- get the sum of negative quantity from InventTrans by considering datePhysical as daterange(between today and end of last year)

    For a given item(variant), from the current OnhandInventory deduct the summed up positive quantity and add the summed up negative quantity to get onHand value on end of last year i.e on 12/31/2016.

    Perform same logic by(i.e looping through inventTrans table) considering the daterange as 1/1/2016 to 12/31/2016.

    Hope this helps you.

    Thanks,

    Chaitanya Golla

  • Community Member Profile Picture
    on at

    Thanks for the reply, Would it be as simple as this below (I don't need by Warehouse):

    --Ending balance in 2016

    select itemid, sum(qty)

    from inventTrans

    Where DatePhysical < 2017/1/1

    Group by ItemID

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Yeah, but this

    -Ending balance in 2016

    select itemid, sum(qty) // Consider sign as I stated two loops

    from inventTrans

    Where DatePhysical < 1/31/2016

    and datePhysical > 1/1/2016

    Group by ItemID

    Try and let us know if you face any issue.

    Thanks,

    Chaitanya Golla

  • Guy Terry Profile Picture
    28,924 Moderator on at

    Be aware that DatePhysical is the date of the physical update (product receipt, packing slip). If you're using 'Picked' or 'Registered' (and not posting the physical update on the same day those things are happening), and if you want Picked or Registered events to be considered in this On-hand quantity calculation, then you'll not be able to do that with InventTrans alone.

    I don't actually know how you would do it, but I thought it worth mentioning this limitation!

  • Community Member Profile Picture
    on at

    Right right, I'm having trouble getting the balance for a particular date using just the inventtrans. I tried the two loops like Golla suggested, but no luck. Any suggestions? Thanks for the help.

  • Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Can you let us know where you struck/provide your code, will try to fix it.

    Thanks,

    Chaitanya Golla

  • Community Member Profile Picture
    on at

    Below is the code. The beginning of 2016 on hand values are off. I'm also trying to get the amount purchased and sold in 2016. I broke it into positive and negative values like you mentioned. Thanks in advance

    select INVENTTABLE.itemid ,

                                   ECORESPRODUCTTRANSLATION.NAME,

                                   CAST( isnull( BOHI.BegOnHand,0) AS DECIMAL(18,2))BegOnHand ,  

                                   CAST( isnull(P.QtyPurchased,0)AS DECIMAL(18,2)) QtyPurchased ,

                                   CAST( isnull(s.QTYSOLD,0)AS DECIMAL(18,2)) QTYSOLD ,

                                   CAST( isnull( EOHI.EndOnHand,0)AS DECIMAL(18,2)) EndOnHand

    from INVENTTABLE                

                   --Beginning  on hand in 2016

                   left outer join (                                  

                                   select itemid,  isnull(SUM(qty),0)BegOnHand

                                   from INVENTTRANS

                                   where  DATEPHYSICAL < '2016-1-1'  

                                   group by ITEMID )BOHI

                                                   on bohi.ITEMID = INVENTTABLE.ITEMID

                   --SOLD

                   left outer join (                  

                                   select ITEMID,  isnull(SUM(QTY),0)*-1 QTYSOLD

                                   from INVENTTRANS

                                   where DATEPHYSICAL >= '2016-1-1' AND  DATEPHYSICAL <  '2017-1-1' and QTY  < 0

                                   GROUP BY ITEMID )S

                                                   on s.ITEMID = INVENTTABLE.ITEMID

                   --PURCHASED

                   left outer join (                  

                                   select ITEMID,  isnull(SUM(QTY),0) QtyPurchased

                                   from INVENTTRANS

                                   where  DATEPHYSICAL >= '2016-1-1' AND  DATEPHYSICAL <  '2017-1-1' and QTY  > 0

                                   GROUP BY ITEMID )P

                                                   ON P.ITEMID = INVENTTABLE.ITEMID

    --Ending on hand in 2016

                   left outer join (

                                   select itemid, ISNULL( SUM(qty),0)EndOnHand

                                   from INVENTTRANS

                                   where  DATEPHYSICAL < '2017-1-1' and STATUSISSUE <> 7

                                   group by ITEMID)EOHI

                                                                   ON EOHI.ITEMID = INVENTTABLE.ITEMID

                   join ECORESPRODUCT

                                   on inventtable.PRODUCT = ecoresproduct.RECID

                   join ECORESPRODUCTTRANSLATION

                                   on ECORESPRODUCTTRANSLATION.PRODUCT = ecoresproduct.RECID

    where ( BOHI.BegOnHand <> 0) or ( P.QtyPurchased <> 0) or( s.QTYSOLD <> 0) or (EOHI.EndOnHand <> 0 )

    Order by inventtable.ITEMID

  • Guy Terry Profile Picture
    28,924 Moderator on at

    Some general comments. When writing SQL against AX tables, you should consider PARTITION and DATAAREAID....even if your AX environment has only one Partition and one company. All the SQL indexes will have these two fields in, and you'll want to let SQL use indexes when it can, right?

    DATAAREAID is the AX Company ID. You can find the value for Partition in the dbo.Partition table. It's probably the RecId of the 'Initial' partition.

    Specifically on this query, you are only interested in inventory transactions which are Sold, Deducted, Purchased or Received. STATUSISSUE and STATUSRECEIPT are the relevant fields.

    I have added all this into your SQL. Er, check I did it right; your SQL appears to be of a much higher standard than mine!

    https://pastebin.com/iSdHsT3V

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans