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

Top 10 customers - SQL view period wise

(0) ShareShare
ReportReport
Posted on by

Does anyone have this view or the script. Mine one is giving trouble - June is Period 1.. Please suggest ..thx

 

alter view Top_10_Customer_By_Sales_CA

 

 

as

 

 

 

 

 

 

Select

 

 

CM.CUSTNAME, RM.CUSTNMBR,sum(RM.[Sales_Amount]) as Sales, case month(RM.GLpostdt)

when 1 then 8

when 2 then 9

when 3 then 10

when 4 then 11

when 5 then 12

when 6 then 1

when 7 then 2

when 8 then 3

when 9 then 4

when 10 then 5

when 11 then 6

else 7 end as

'Period_Name',

 

 

case

 

 

when month(RM.GLpostdt) >=7

 

 

then year(RM.GLPOSTDT)+1

 

 

else year(RM.GLPOSTDT) end as 'Year'

 

 

from

 

 

(SELECT

 

 

 

 

 

 

CUSTNMBR,DOCDATE, GLPOSTDT,DOCNUMBR,RMDTYPAL, ORTRXAMT, CURTRXAM, SLSAMNT, FRTAMNT,MISCAMNT, TAXAMNT, TRDISAMT, VOIDSTTS,

 

 

case

 

 

when RMDTYPAL in (1,3,4) then ORTRXAMT when RMDTYPAL in (7,8) then -1*ORTRXAMT

 

 

else 0 end Sales_Amount

 

 

FROM RM20101) RM

 

 

Left outer join

 

 

RM00101 CM on CM.CUSTNMBR = RM.CUSTNMBR

 

 

 

 

group by month(RM.GLpostdt),Year(RM.GLPOSTdt), RM.CUSTNMBR, CM.CUSTNAME

 

 

 

 

 

 

Union all

 

 

Select

 

 

CM.CUSTNAME, RM.CUSTNMBR,sum(RM.[Sales_Amount]) as Sales , case month(RM.GLpostdt)

when 1 then 8

when 2 then 9

when 3 then 10

when 4 then 11

when 5 then 12

when 6 then 1

when 7 then 2

when 8 then 3

when 9 then 4

when 10 then 5

when 11 then 6

else 7 end as

'Period_Name',

 

 

 

case

 

 

when month(RM.GLpostdt) >=7 then year(RM.GLPOSTDT)+1 else year(RM.GLPOSTDT) end as 'Year'

 

 

from

 

 

(SELECT

 

 

CUSTNMBR,DOCDATE, GLPOSTDT,DOCNUMBR,RMDTYPAL, ORTRXAMT, CURTRXAM, SLSAMNT, FRTAMNT,MISCAMNT, TAXAMNT, TRDISAMT, VOIDSTTS,

 

 

case

 

 

when RMDTYPAL in (1,3,4) then ORTRXAMT when RMDTYPAL in (7,8) then -1*ORTRXAMT else 0 end Sales_Amount

 

 

FROM RM30101) RM

 

 

Left outer join

 

 

RM00101 CM on

 

 

CM.CUSTNMBR = RM.CUSTNMBR

 

 

 

 

group by month(RM.GLpostdt),Year(RM.GLPOSTdt), RM.CUSTNMBR, CM.CUSTNAME

*This post is locked for comments

I have the same question (0)
  • L Vail Profile Picture
    65,271 on at

    Hi,

    What kind of trouble are you having - how are the results different from what you are looking for? Also, it looks like you are using a fiscal year, is that correct. The query posted with so many blank lines I didn't carefully read through it until I knew what you thought was wrong.

    Kind regards,

    Leslie

  • Community Member Profile Picture
    on at

    Hi Leslie,

    Thanks for the reply. Actually, I am looking for a simple report - Top 10 customers (sales wise) for a range of periods for a given fiscal year. I developed the above view (also in SSRS) but the result is inconsistent. Specially, the periods are not working properly. So, when I test it for July 2015 (period 2 of the Fiscal year 2016), it does not give me the desired result. So, I was wondering if anyone has done this kind of work in the past.

    Thanks for your help.

    John

  • Suggested answer
    L Vail Profile Picture
    65,271 on at

    John,

    I'm bad, I have still not looked carefully at your view, but are you getting the period by comparing the document date with the fiscal period setup table? I've never seen that go wrong. Also, which date field are you using and make sure you're not looking at the SOP tables.

    Kind regards,

    Leslie

  • Community Member Profile Picture
    on at

    Hi Leslie,

    I am looking at the GL posting date in RM20101 and RM30101. Actually, I am not joining the fiscal period table with the date instead I m just taking out the month and year from the date and I think this is the place where I have the overlap (just guessing). I am saying take the month and year from th GL posting date and give me the year as year-1 if the period no. > 7 (June is 1st period, so if it is Jan ie period 8, give me the fiscal year as 2014 if the date was Jan 2015 because it belonged to that FY). I ll look into it tomorrow again and see if i could join the fiscal period table with the gl posting date.

    thx,

    john

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans