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 :
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)

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,320 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.

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: group by records based on a date field

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

  • deepak31 Profile Picture
    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

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator 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.

  • Martin Dráb Profile Picture
    236,320 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.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,100

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 890 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 633 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans