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 :
Small and medium business | Business Central, N...
Suggested answer

Re: How to get values from multiple tables in Excel Report for Business Central

(0) ShareShare
ReportReport
Posted on by 76
Hi, 
 My requirement is to create an excel report with many columns from different tables. So i wrote a code like this:
report 50100 /GSTR1 Report/
{
    ApplicationArea = All;
    Caption = 'GSTR1 Excel';
    UsageCategory = /ReportsAndAnalysis/;
    ExcelLayout = 'GSTR1 Excel.xlsx';
    DefaultLayout = Excel;
    dataset
    {
        dataitem(/Sales Invoice Header/; /Sales Invoice Header/)
        {     
 
            column(Receiver_Name; /Bill-to Name/)
            {
            }
            column(Invoice_Number; /No./)
            {
            }
            column(Posting_Date; /Posting Date/)
            {
            }
            column(Place_of_Supply; /Location State Code/)
            {
            }
            dataitem(/Sales Invoice Line/; /Sales Invoice Line/)
            {
                DataItemLink = /Document No./ = field(/No./);
                DataItemLinkReference = /Sales Invoice Header/;
                DataItemTableView = sorting(/Document No./);
                column(Taxable_Value; Amount)
                {
                }
                column(Rate; Rate)
                {
                }
                column(CGST; CGST)
                {
                }
                column(SGST; SGST)
                {
                }
                column(IGST; IGST)
                {
                }
            }
            dataitem(/Cust. Ledger Entry/; /Cust. Ledger Entry/)
            {
                DataItemLink = /Document No./ = field(/No./);
                DataItemLinkReference = /Sales Invoice Header/;
                DataItemTableView = sorting(/Document No./);
                column(Invoice_Value; Amount)
                {
 
                }
            }           
            dataitem(Customer; Customer)
            {
                DataItemLink = /No./ = field(/Sell-to Customer No./);
                DataItemLinkReference = /Sales Invoice Header/;
                DataItemTableView = sorting(/No./);
                column(GST_Registration_No_; /GST Registration No./)
                {
 
                }
            }
            trigger OnAfterGetRecord()
            var
            begin
                DGST.Reset();
                DGST.SetRange(/Document No./, /No./);
                CGST := 0;
                SGST := 0;
                IGST := 0;
 
                if DGST.FindFirst() then
                    repeat
 
                        if DGST./GST Component Code/ = 'CGST' then begin
                            CGST += -DGST./GST Amount/;
                            SGST += -DGST./GST Amount/;
                            IGST := 0;
                            Rate := DGST./GST %/;
                        end
                        
                        if DGST./GST Component Code/ = 'IGST' then begin
                            IGST += -DGST./GST Amount/;
                            Rate := DGST./GST %/;
                            CGST := 0;
                            SGST := 0;
                        end;
 
                    until DGST.Next() = 0
 
                else begin
                    CGST := 0;
                    SGST := 0;
                    IGST := 0;
                    Rate := 0;
 
                end;
            end;
 
        }
    }
    var
        CGST: Decimal;
        SGST: Decimal;
        IGST: Decimal;
        Rate: Decimal;
        CustLedEnt: Record /Cust. Ledger Entry/;
        DGST: Record /Detailed GST Ledger Entry/;
        Cust: Record Customer;
        CustGSTRegNo: Code[20];
        InvoiceValue: Decimal;
        GST_Registration_No_: Code[20];
}
 
If I run the above code I get output as 
 
My requirement is to get values in columns in One line. but now getting Invoice value in one line, GST Registration No. in one line and all other field values in another line for the same document no. Please suggest me to all values in single line. 
I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,071 Moderator on at
    Re: How to get values from multiple tables in Excel Report for Business Central
    You will get one line for each data item that is nested in your report.
    So if you want to have it all in one line you need to use only one data item., Then in the OnAfterGetRecord trigger for that data item you need to collect all the other data you want to report, put those data into variables that you then again use on your report layout.
  • Suggested answer
    YUN ZHU Profile Picture
    94,303 Super User 2025 Season 2 on at
    Re: How to get values from multiple tables in Excel Report for Business Central
    If you insist on using Excel Layout, you need to use Excel formulas to do some processing in Excel. Here is a simple example, hoping to give you some hints.
     
    Thanks.
    ZHU

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,791

#2
YUN ZHU Profile Picture

YUN ZHU 2,091 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 2,090

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans