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

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Find the last purchase details of purchased items

(0) ShareShare
ReportReport
Posted on by 1,893

Hello Experts,

Is there any possibilility to find the last purchase details of raw materials based on the posted purchase invoice.
I am trying with SQL server query but query is not 100% correct please give me some idea to resolve it.

My query is below.

select max(PIH.[Posting Date]),PIH.[Currency Code],[Direct Unit Cost]-([Line Discount Amount]/nullif(Quantity,0)) "Last Purchase Price",[Unit Cost (LCY)],PIL.No_ "Item No.",Description,[Document No_],
case PIH.[Incom Terms] when 0 then ' ' when 1 then 'Ex-Works' when 2 then 'FCA' when 3 then 'CPT' when 4 then 'CIP' when 5 then 'DAT' when 6 then 'DAP' when 7 then 'DDP'
when 8 then 'FAS' when 9 then 'FOB' when 10 then 'CFR' when 11 then 'CIF' when 12 then 'DAF'
when 13 then 'DES' when 14 then 'DEQ' when 15 then 'DDU' when 16 then 'FOR' end as [Incom Terms]
from [India Private Limited$Purch_ Inv_ Line] PIL
left outer join [India Private Limited$Purch_ Inv_ Header] PIH on PIH.No_ = PIL.[Document No_]
where PIL.No_<>'' and PIL.Type=2
group by PIH.[Currency Code],[Direct Unit Cost]-([Line Discount Amount]/nullif(Quantity,0)),[Unit Cost (LCY)],PIL.No_ ,Description,[Document No_],
PIH.[Incom Terms]

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at
    RE: Find the last purchase details of purchased items

    You can write a code in NAV also.

    User Item table and Purchase Invoice Line table.

    ltPurchInvLine.SETRANGE(Type,ltPurchInvLine.Type::Item);

    ltPurchInvLine.SETRANGE("No.","No.");

    ltPurchInvLine.SETRANGE("Variant Code","Variant Code");

    IF ltPurchInvLine.FINDLast THEN

     //Write code to get details from that invoice line

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Find the last purchase details of purchased items

    Check the Item Value Entries for the Document Type Purchase Invoice.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans