web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Increase ProcessReport() Performance (optimize the Query) - SSRS Report

(0) ShareShare
ReportReport
Posted on by 353

Hi -

  I have a report that produces the data correctly the problem is the execution time, it takes a long time to generate the report. look at the screen shot below for my process report method. 

     while select * from inventValueTransUnionAllParent
       join *  from inventDimParent
         group by InventLocationId,InventSiteId  ASC
            where inventValueTransUnionAllParent.inventDimId == inventDimParent.inventDimId
                  && inventDimParent.InventLocationId != ''
                  && inventDimParent.InventLocationId != 'N/A'
        {
             ttsBegin;
             MTRA_InventoryValueReportTmp.InventoryFinancialAmount         = this.populateFinancialAmount(fromDate,toDate,inventDimParent.InventLocationId);
            // MTRA_InventoryValueReportTmp.InventoryFinancialQty            = this.populateFinancialQty(fromDate,toDate,inventDimParent.InventLocationId);
            // MTRA_InventoryValueReportTmp.InventoryPhysicalPostedAmount    = this.populatePhysicalAmount(fromDate,toDate,inventDimParent.InventLocationId);
            // MTRA_InventoryValueReportTmp.InventoryPhysicalPostedQty       = this.populatePhysicallQty(fromDate,toDate,inventDimParent.InventLocationId);
             MTRA_InventoryValueReportTmp.InventLocationId                 = inventDimParent.InventLocationId;
             MTRA_InventoryValueReportTmp.InventSiteId                     = inventDimParent.InventSiteId;

             MTRA_InventoryValueReportTmp.insert();
             ttsCommit;
       }


Now for the individual methods which populated the tmp table buffer. 

public CostAmount populateFinancialAmount(FromDate _fromDate, ToDate _toDate, InventLocationId _InventLocationId)
{
    CostAmount Amounts = 0;

      while select * from inventValueTransUnionAll
          where  inventValueTransUnionAll.TransDate >= _fromDate
            && inventValueTransUnionAll.TransDate <= _toDate
            && (inventValueTransUnionAll.unionAllBranchId == 6)
        join * from inventdim
          where inventValueTransUnionAll.inventDimId == inventdim.inventDimId
           && inventDim.InventLocationId == _InventLocationId
    {
        {
            Amounts = Amounts + inventValueTransUnionAll.Amount;
        }
    }
        while select * from inventValueTransUnionAll
          where  inventValueTransUnionAll.TransDate >= _fromDate
            && inventValueTransUnionAll.TransDate <= _toDate
            && (inventValueTransUnionAll.unionAllBranchId == 5)
        join * from inventDim
          where inventValueTransUnionAll.inventDimId == inventDim.inventDimId
           && inventDim.InventLocationId == _InventLocationId
    {
        {
            Amounts = Amounts + inventValueTransUnionAll.Amount;
        }
    }// working query

    return Amounts;
}


What changes I can make in my query/ Methods to optimize the report results ?

Any suggestions will be really helpfull

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    One obvious optimization is in populateFinancialAmount(). You fetch all fields of all records matching the conditions, while you really want just a single value - the sum of Amount. That's exactly what the aggregation function sum() is for. For example:

    select sum(Amount) from inventValueTransUnionAll
        where inventValueTransUnionAll.TransDate >= _fromDate
           && inventValueTransUnionAll.TransDate <= _toDate
           && inventValueTransUnionAll.unionAllBranchId == 6
        exists join from inventdim
          where inventValueTransUnionAll.inventDimId == inventdim.inventDimId
           && inventDim.InventLocationId == _InventLocationId;
    
    amounts = inventValueTransUnionAll.Amount;

    And because you have it in a while loop, you fetch all fields of all records many times, which is an enormous waste of resources.

  • Muhammad_Ali Profile Picture
    353 on at

    Thanks Martin for your advice. It did help me with performance. Do you think I can possibly make any changes in my ProcessReport() query to enhance performance even further ?

    Thanks

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    If you have two queries in your four populate* methods, it means eight queries for each record from the while select. If it returns 100 records, it means 800 extra records. This is what I would try to reduce, possibly even creating a single view with all the sums (calculated in computed columns).

    You should also look at performance of individual queries. Start with Trace Parser and if you notice a problem, look at the execution plan in SQL Server Management Studio.

  • Muhammad_Ali Profile Picture
    353 on at

    hmm Thanks Martin I will look into this now.

    Much Appreciated

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans