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

Announcements

No record found.

News and Announcements icon
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
    239,040 Most Valuable Professional on at

    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

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

  • deepak31 Profile Picture
    45 on at
    [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

    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
    239,040 Most Valuable Professional on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans