Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Search values ??in other months if the current one does not have

(0) ShareShare
ReportReport
Posted on by
Hi
I'm developing an activity that I need to develop the following rule:
Check the last highest unit purchase value of the item entered in the current month. 
(VendInvoiceTrans).PurchPrice of the Item (VendInvoicetrans).ItemId , if there is no purchase record in the current month,
check the previous month and so on. How could I do this on Ax 2012?
  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Search values ​​in other months if the current one does not have

    I'm glad we were able to resolve your issue. You can close the topic by verify the answer.

  • Community Member Profile Picture
    on at
    RE: Search values ​​in other months if the current one does not have
    Ergun ahin,
    Thank you very much, your answer is exactly what I needed, it worked.
  • Verified answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Search values ​​in other months if the current one does not have

    The question sounded very familiar. It's like I answered once .
    In the other question, account was involved, so I included the header in the answer.
    If it's just the item, the process is easier. You can find the last record of this item with a simple select, instead of looking for the last record month by month. After you find the last record, what you need to do is to apply a one-month range with the date(month) information of that record and find the maximum price.

    ItemId _itemId = "";
        VendInvoiceTrans vendInvoiceTrans;
        FromDate fromDate;
        ToDate toDate;
        ;
        select firstOnly vendInvoiceTrans
        order by InvoiceDate Desc
            where   vendInvoiceTrans.ItemId                     == _itemId;
        
        fromDate = mkDate(1,mthofyr(vendInvoiceTrans.InvoiceDate),year(vendInvoiceTrans.InvoiceDate));
        toDate   = endMth(vendInvoiceTrans.InvoiceDate);
    
        select maxof(PurchPrice) from vendInvoiceTrans
                where   vendInvoiceTrans.InvoiceDate                >= fromDate
                &&      vendInvoiceTrans.InvoiceDate                <= toDate
                &&      vendInvoiceTrans.ItemId                     == _itemId;
        info(strFmt("%1",vendInvoiceTrans.PurchPrice));

  • André Arnaud de Calavon Profile Picture
    294,165 Super User 2025 Season 1 on at
    RE: Search values ​​in other months if the current one does not have

    Hi Euler,

    Do you need the last or highest purchase price? The current month is per calendar month or a 30 day running period?

    Curiosity: What is the purpose for this requirement?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,165 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans