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 :
Microsoft Dynamics NAV (Archived)

Grouping Dates

(0) ShareShare
ReportReport
Posted on by

Hi All

I am using Microsoft Dynamics NAV 2013 , I also use Tableau to connect to my relational tables in SQL which is my data source for NAV, I am select data from the Value Entry , Item Ledger Entry and Item tables into a new table. The Value Entry Table and Item Ledger Entry Table joins to the Item table

The insert into query into the new table takes a while and then times out. then I have figured by grouping the date column will speed up the process which it does as I have tested the query by grouping the date , see script below

USE SPIERLIVE
GO

SELECT DATEPART(Year, d.[Posting Date]) Year, DATEPART(Month, d.[Posting Date]) Month,
       d. [Source No_], c.[Company], a.[Inventory Posting Group], a.[Item Category Code], c.[Variant Code],d.[Global Dimension 1 Code] AS [Brand Class No],
	   d.[Sales Amount (Actual)], d.[Cost Amount (Actual)], d.[Expected Cost],d.[Sales Amount (Expected)], d.[Cost Amount (Expected)],
	   b.[Quantity], b.[Remaining Quantity], c.[Quantity] AS [WineMS Quantity], 
	   c.[Cost Amount] AS  [WineMS Cost Amount]

FROM [dbo].[Spier Live$Item Ledger Entry] b, [dbo].[Spier Live$Item] a, [dbo].[WineMS Inv_Transaction Tbl] 
     c, [dbo].[Spier Live$Value Entry] d
WHERE  b.[Item No_] = a.[No_]
AND  c.[Item No] = a.[No_]

GROUP BY b.[Quantity], b.[Remaining Quantity],
	     c.[Company],c.[Variant Code], c.[Global Dimension 1 Code], c.[Quantity], 
	     c.[Cost Amount],
	     DATEPART(Year, d.[Posting Date]), DATEPART(Month, d.[Posting Date]),
	   

   I do not know if this is the correct way of doing the grouping for the dates. Our financial Year/Fiscal year
starts on the 1 July of every year and ending on 30 June of every year.
The DATEPART(Year, d.[Posting Date]),does group the year and it does display the years ,
however the DATEPART(Month, d.[Posting Date]), displays the month number e.g. month 6 for example and not the name of the month e.g. January

how can I get the month Name displayed. Should I also group the value columns and only the posting date

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Grouping Dates

    Ledger Entry tables have the primarykey has Entry No. which is unique for every transactions, by grouping on any other fields you are losing the data.

  • Community Member Profile Picture
    on at
    RE: Grouping Dates

    Thanks Suresh I will add group on the entry no column, However , I have a few columns in my select statement , is it possible to only group by one column , surely I will get an error when executing the script

  • Community Member Profile Picture
    on at
    RE: Grouping Dates

    Thanks for your suggestion and guiding me on the right direction , I have now found a work around

  • Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Grouping Dates

    Glad to help

  • Community Member Profile Picture
    on at
    RE: Grouping Dates

    My new script

    SELECT  
    /*Value Entry Table */
            MAX(a.[Posting Date]), MAX(a.[Inventory Posting Group]), MAX(a.[Global Dimension 1 Code] AS [Brand Class No]),
    		MAX(a.[Valued Quantity]), MAX(a.[Sales Amount (Actual)]), MAX(a.[, a.Cost Amount (Actual)]),
    		MAX(a.[Expected Cost]), MAX(a.[Sales Amount (Expected)]),
    		MAX(a.[Cost Amount (Expected)]),
    /*Item Ledger Entry*/
            
    		MAX(b.[Entry No_]), MAX(b.[Source No_]), MAX(b.[Global Dimension 1 Code] AS [Brand Class Code]), MAX(b.[Country_Region Code]),
    		MAX(b.[Quantity]), MAX(b.[Remaining Quantity]), MAX(b.[Variant Code])
            
    FROM    [dbo].[Spier Live$Value Entry] a, [dbo].[Spier Live$Item Ledger Entry] b
        
    GROUP BY 
            a.[Entry No_]


  • Verified answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Grouping Dates

    Mark the query as answered if it is resolved.  Thanks for sharing.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans