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

Announcements

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
    240,312 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
    240,312 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 276 Most Valuable Professional

#3
Anton Venter Profile Picture

Anton Venter 225 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans