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 :
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 86
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. 
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at
    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
    103,264 Super User 2026 Season 2 on at
    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

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 August Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 715 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 452 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 371 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans