Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

group by records based on a date field

(0) ShareShare
ReportReport
Posted on by 45

I need to create a excel report   from  inventtrans table,, i nee to get the record as  month wise group by using datePhysical field,againt each item

SELECT ITEMID, DATEPART(Year,DATEPHYSICAL) as year,DATEPART(MONTH,DATEPHYSICAL) as month,SUM(QTY)  FROM INVENTTRANS
				WHERE INVENTTRANS.ITEMID ='101'
				group by INVENTTRANS.ITEMID, DATEPART(Year,DATEPHYSICAL),DATEPART(MONTH,DATEPHYSICAL)

How can i achieve this in x (D365FO)

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: group by records based on a date field

    You didn't tell us how you designed your view and what you mean by "incorrect values", but the join looks wrong to me.

    I would expect that your view contains year and month values for inventory transactions and than you'll join InventTrans with the view over InventTransId. Your query returns the same year and month for all transactions with the same item. regardless of the value of DatePhysical field of the given transaction.

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: group by records based on a date field

    Can you use the join in SSMS also? Because if you use join sometimes the returning data will change. So try giving same query in both places and check.

  • deepak31 Profile Picture
    deepak31 45 on at
    RE: group by records based on a date field
    [quote

    Create a view with computed columns, where you'll extract the year and month from DatePhysical.

    Then use a select statement to get data from the view and use those computed columns in 'group by' clause.

    [/quote

    Here i need to find  the sum of Quantity and sum of costvalue,i tried with this select statemnt ,but those values are in correct,can you pls help me to correct this

    while select ItemId,DatePhysical,sum(Qty),sum(CostAmountPosted),sum(CostAmountAdjustment) from inventTrans
                        group by inventTrans.ItemId,inventview.MonthInDate,inventview.YearInDate
                        order by inventview.YearInDate desc
                        join inventview
                        where inventTrans.ItemId == inventview.ItemId

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: group by records based on a date field

    You can create Static or dynamic query which will solve this.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: group by records based on a date field

    Create a view with computed columns, where you'll extract the year and month from DatePhysical.

    Then use a select statement to get data from the view and use those computed columns in 'group by' clause.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans