Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Report Required with Formulated Closing Balance Column

Posted on by Microsoft Employee

Dear All

 

I need a report in Microsoft Navision using following tables

 

Cust. Ledger Entry (21)

Detailed Cust. Ledg. Entry (379)

 

The fields required are as follows:-

 

Posting Date (From Cust. Ledger Entry)

Document No. (From Cust. Ledger Entry)

External Document No.

Debit_Amount_LCY                    whose CalcFormula is as follows:-

Sum("Detailed Cust. Ledg. Entry"."Debit Amount (LCY)" WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Entry Type=FILTER(<>Application),Posting Date=FIELD(Date Filter)))

 

Credit_Amount_LCY                   whose CalcFormula is as follows:-

Sum("Detailed Cust. Ledg. Entry"."Credit Amount (LCY)" WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Entry Type=FILTER(<>Application),Posting Date=FIELD(Date Filter)))

 

RemainingAmt                              whose CalcFormula is as follows:-

Sum("Detailed Cust. Ledg. Entry".Amount WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter)))

 

Closing_Balance                          

The value in first row of Closing Balance Column should be Debit_Amount_LCY- Credit_Amount_LCY

The value of closing balance in subsequent rows should be calculated as follows:-

Value of closing balance in previous row + Debit_Amount_LCY- Credit_Amount_LCY.

 

When we apply Posting Date filter (start and end date):-

 

  1. A new line to be created (row no. 1) with Posting Date equal to Start Date of the Filter. Suppose starting date is 01-09-2017 and ending date is current date
  2. Closing Balance Value in the last row of the data just before the starting date of “from date filter” should serve as Opening Balance in Debit Column if positive else Credit Column if negative and value in the closing balance should be Debit_Amount_LCY - Credit_Amount_LCY. In row 1 the Posting Date is 01 September 2017, External_Document_No = Opening Balance, Debit_Amount_LCY = as per specified calculation, Credit_Amount_LCY = as per specified calculation, Remaining_Amount = as per specified calculation
  3. In next line same formula should apply i.e. Value of closing balance in previous row + Debit_Amount_LCY- Credit_Amount_LCY
  4. A new line to be created after last row.
  5. In the newly created row if the value of closing balance (above this row) is positive then External_Document_No = Amount Receivable else External_Document_No = Amount Refundable. The value of closing balance in this row should be equal to value just above it.
  6. The following is the format of output

 

 

 

 

Posting Date

Document_No

External Document No_

Debit_Amount_LCY

Credit_Amount_LCY

RemainingAmt

closing_balance

04-01-17

NULL

NULL

637089.1

NULL

NULL

637089.1

04-06-17

PNX/17-18/M0002

Email

1472

0

1472

638561.1

04-07-17

PNX/17-18/M0016

Email

1281

0

1281

639842.1

04-10-17

PNX/17-18/M0041

Email

23475

0

23475

663317.1

04-15-17

PNX/17-18/M0176

Email

6879

0

6879

670196.1

04-15-17

PNX/17-18/M0195

Email

2945

0

2945

673141.1

04-15-17

PNX/17-18/M0197

Email

1880

0

1880

675021.1

04-15-17

PSCN/RV-17-18/000003

 

0

6879

-6879

668142.1

04-21-17

PNX/17-18/M0347

Email

3012

0

3012

671154.1

04-21-17

PNX/17-18/M0348

Email

84

0

84

671238.1

04-24-17

BV/16-17/03/00986

497398

0

150000

-150000

521238.1

04-27-17

PNX/17-18/M0452

Email

37422

0

37422

558660.1

04-27-17

PNX/17-18/T0200

Email

369

0

369

559029.1

05-19-17

PNX/17-18/M0906

Email

30192

0

30192

589221.1

05-19-17

PNX/17-18/M0907

Email

12957

0

12957

602178.1

05-19-17

PNX/17-18/T0426

Email

194

0

194

602372.1

05-20-17

PNX/17-18/T0434

Email

1100

0

1100

603472.1

05-23-17

PNX/17-18/M0974

Email

17486

0

17486

620958.1

05-23-17

PNX/17-18/M0981

Email

4374

0

4374

625332.1

05-23-17

PNX/17-18/T0459

Email

2635

0

2635

627967.1

05-25-17

PNX/17-18/M1037

Email

1690

0

1690

629657.1

06-13-17

PNX/17-18/M1443

Email

8457

0

8457

638114.1

06-13-17

PNX/17-18/M1444

Email

2481

0

2481

640595.1

06-13-17

PNX/17-18/M1445

Email

2007

0

2007

642602.1

06-19-17

PNX/17-18/M1594

Email

3646

0

3646

646248.1

06-19-17

PNX/17-18/T0782

Email

86

0

86

646334.1

06-23-17

PNX/17-18/M1709

Email

24886

0

24886

671220.1

06-23-17

PNX/17-18/M1715

Email

16425

0

16425

687645.1

06-23-17

PNX/17-18/T0842

Email

480

0

480

688125.1

06-23-17

PSCN/RV-17-18/000012

 

0

24886

-24886

663239.1

06-28-17

PNX/17-18/T0865

AURA/2017-18/PNX06/10

10408

0

10408

673647.1

07-27-17

PNX/17-18/G0486

 

444

0

444

674091.1

07-27-17

PNX/17-18/G0487

 

31999

0

31999

706090.1

07-31-17

PNX/17-18/G0570

 

19854

0

19854

725944.1

08-18-17

PNX/17-18/G0919

 

4575

0

4575

730519.1

08-22-17

PNX/17-18/G1004

 

5191

0

5191

735710.1

08-24-17

PNX/17-18/G1059

 

2722

0

2722

738432.1

08-24-17

PNX/17-18/G1060

 

12581

0

12581

751013.1

08-28-17

BV/17-18/08/00449

497399

0

250000

-250000

501013.1

08-28-17

PNX/17-18/G1115

 

3565

0

3565

504578.1

09-02-17

PNX/17-18/G1296

 

59076

0

59076

563654.1

09-02-17

PNX/17-18/G1297

 

809

0

809

564463.1

09-02-17

PNX/17-18/G1303

 

2845

0

2845

567308.1

09-05-17

PNX/17-18/G1360

 

2680

0

2680

569988.1

09-19-17

PNX/17-18/G1646

 

4738

0

4738

574726.1

09-19-17

PNX/17-18/G1647

 

604

0

604

575330.1

09-22-17

PNX/17-18/G1744

 

1740

0

1740

577070.1

09-27-17

PNX/17-18/G1831

 

17438

0

17438

594508.1

09-27-17

PNX/17-18/G1849

 

3700

0

3700

598208.1

09-27-17

PNX/17-18/G1850

 

1361

0

1361

599569.1

09-28-17

PNX/17-18/G1867

 

2199

0

2199

601768.1

10-23-17

PNX/17-18/G2159

 

4803

0

4803

606571.1

NULL

NULL

Amount Receivable

NULL

NULL

NULL

606571.1

 

 

 

 

Pl. be informed that following query is running successfully in SQL but I don’t know how to convert the same in .net format and implement in NAV. If the sql query would have worked in Excel it would have served my purpose but while using the query in excel I am getting the error

"The query didnot run or the database table could not be opened”.

Kindly treat me as a beginner in reports of Microsoft Dynamics Nav guide me step by step to make the report as per above requirement.

 

 

 

SELECT *

       ,Sum(A.Balance) OVER (

              ORDER BY A.[Posting Date] ASC

                     ,A.[Document No_]

              ) Closing_Balance

INTO #tmp

FROM (

       SELECT [PPIPL$Cust_ Ledger Entry].[Customer No_]

              ,[PPIPL$Cust_ Ledger Entry].[Posting Date]

              ,[PPIPL$Cust_ Ledger Entry].[Document No_]

              ,[PPIPL$Cust_ Ledger Entry].[External Document No_]

              ,[PPIPL$Cust_ Ledger Entry].Description

              ,REPLACE(SUM(CASE

                                  WHEN (

                                                ([PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_])

                                                AND ([PPIPL$Detailed Cust_ Ledg_ Entry].[Entry Type] <> 2)

                                                )

                                         THEN [PPIPL$Detailed Cust_ Ledg_ Entry].[Debit Amount (LCY)]

                                  ELSE 0

                                  END), ',', '') Debit_Amount_LCY

              ,REPLACE(SUM(CASE

                                  WHEN (

                                                ([PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_])

                                                AND ([PPIPL$Detailed Cust_ Ledg_ Entry].[Entry Type] <> 2)

                                                )

                                         THEN [PPIPL$Detailed Cust_ Ledg_ Entry].[Credit Amount (LCY)]

                                  ELSE 0

                                  END), ',', '') Credit_Amount_LCY

              ,SUM(CASE

                           WHEN (

                                         ([PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_])

                                         AND ([PPIPL$Detailed Cust_ Ledg_ Entry].[Entry Type] = 1)

                                         )

                                  THEN [PPIPL$Detailed Cust_ Ledg_ Entry].[Amount]

                           ELSE 0

                           END) AS RemainingAmt

              ,(

                     COALESCE(CONVERT(FLOAT, REPLACE(SUM(CASE

                                                       WHEN (

                                                                     ([PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_])

                                                                     AND ([PPIPL$Detailed Cust_ Ledg_ Entry].[Entry Type] <> 2)

                                                                     )

                                                              THEN [PPIPL$Detailed Cust_ Ledg_ Entry].[Debit Amount (LCY)]

                                                       ELSE 0

                                                       END), ',', '')), 0) - COALESCE(CONVERT(FLOAT, REPLACE(SUM(CASE

                                                       WHEN (

                                                                     ([PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_])

                                                                     AND ([PPIPL$Detailed Cust_ Ledg_ Entry].[Entry Type] <> 2)

                                                                     )

                                                              THEN [PPIPL$Detailed Cust_ Ledg_ Entry].[Credit Amount (LCY)]

                                                       ELSE 0

                                                       END), ',', '')), 0)

                     ) AS balance

       FROM [PPIPL$Cust_ Ledger Entry]

       INNER JOIN [PPIPL$Detailed Cust_ Ledg_ Entry] ON [PPIPL$Cust_ Ledger Entry].[Entry No_] = [PPIPL$Detailed Cust_ Ledg_ Entry].[Cust_ Ledger Entry No_]

       WHERE ([PPIPL$Cust_ Ledger Entry].[Customer No_] = N'C00035')

       GROUP BY [PPIPL$Cust_ Ledger Entry].[Customer No_]

              ,[PPIPL$Cust_ Ledger Entry].[Posting Date]

              ,[PPIPL$Cust_ Ledger Entry].[Document No_]

              ,[PPIPL$Cust_ Ledger Entry].[External Document No_]

              ,[PPIPL$Cust_ Ledger Entry].Description

       ) A

 

--Change the start and end date

DECLARE @StartDate DATE = '2017-04-01';

DECLARE @EndDate DATE=GETDATE();

 

 

DECLARE @Last_Balance_start FLOAT;

DECLARE @Last_Balance_End FLOAT;

 

SELECT TOP (1) @Last_Balance_start = closing_balance

FROM #tmp

WHERE [Posting Date] <= @StartDate

ORDER BY [Posting Date] DESC

 

SELECT TOP (1) @Last_Balance_end = closing_balance

FROM #tmp

WHERE [Posting Date] > @StartDate

       AND [Posting Date] < @EndDate

ORDER BY [Posting Date] DESC

 

SELECT @StartDate [Posting Date]

       ,NULL Document_No

       ,NULL [External Document No_]

       ,CASE

              WHEN SIGN(@Last_Balance_start) = 1

                     THEN @Last_Balance_start

              ELSE NULL

              END AS Debit_Amount_LCY

       ,CASE

              WHEN SIGN(@Last_Balance_start) = - 1

                     THEN @Last_Balance_start

              ELSE NULL

              END AS Credit_Amount_LCY

       ,NULL RemainingAmt

       ,@Last_Balance_start closing_balance

 

UNION ALL

 

SELECT t.[Posting Date]

       ,t.[Document No_]

       ,t.[External Document No_]

       ,t.Debit_Amount_LCY

       ,t.Credit_Amount_LCY

       ,t.RemainingAmt

       ,t.closing_balance

FROM #tmp t

WHERE t.[Posting Date] > @StartDate

       AND t.[Posting Date] < @EndDate

 

UNION ALL

 

SELECT NULL [Posting Date]

       ,NULL Document_No

       ,CASE

              WHEN SIGN(@Last_Balance_end) = 1

                     THEN 'Amount Receivable'

              ELSE 'Amount Refundable'

              END [External Document No_]

       ,NULL Debit_Amount_LCY

       ,NULL Credit_Amount_LCY

       ,NULL RemainingAmt

       ,@Last_Balance_end closing_balance

 

DROP TABLE #tmp

 

Thanking you in advance.

*This post is locked for comments

  • ManishS Profile Picture
    ManishS 6,578 on at
    RE: Report Required with Formulated Closing Balance Column

    Did you check standard report, Customer Trail Balance, Customer Detailed Trial balance.

  • Suggested answer
    AJAnsari Profile Picture
    AJAnsari 5,754 on at
    RE: Report Required with Formulated Closing Balance Column

    Hi,

    What you are looking to do isn't very complex, but I doubt you will get a report made as a response to your question here. That said, here are my suggestions to you:

    - Have your partner or a freelance NAV developer do the report for you (or show you how it's done)

    - Use an Excel based tool like Jet Express which you get with your purchase of NAV, and use its' Table Builder wizard to quickly and create a tabular output joining records from the Customer Ledger Entry and the Detailed Cust. Ledg. Entry tables with desired filters, manual calculations, etc. And the output of this report can be shared, and refreshed within Excel.

    - Alternatively, if you are comfortable with Web Services and Power BI Desktop, you can also do the same in Power BI. But Excel might be more straightforward.

    I hope this helps. If my response has answered your question, please verify by clicking Yes next to "Did this answer your question?"

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans