Querying records by Dimension Set ID

TESDeveloper
Member Posts: 42
I am attempting is to create a page on a role center that calculates the total amount for G/L Entries based on specific dimensions. Currently, the page performs this calculation when it loads.
I have created a query for this purpose, which is functional but not optimized for performance. I'm wondering if there are any ways to improve its efficiency. The function used to read the query serves two purposes: calculating the total amount and displaying the records found in the query. However, during the initial load, I only need to calculate the total amount. I'm unsure if there are is any improvements I can make.
We only need to filter for a maximum of two dimension values.
Query
How I call the Query
I have created a query for this purpose, which is functional but not optimized for performance. I'm wondering if there are any ways to improve its efficiency. The function used to read the query serves two purposes: calculating the total amount and displaying the records found in the query. However, during the initial load, I only need to calculate the total amount. I'm unsure if there are is any improvements I can make.
We only need to filter for a maximum of two dimension values.
Query
query 50000 "Get Actual By Dim." { QueryType = Normal; elements { dataitem(DimensionSetEntry; "Dimension Set Entry") { column(DimensionCode_DimensionSetEntry; "Dimension Code") { } column(DimensionName_DimensionSetEntry; "Dimension Name") { } column(DimensionSetID_DimensionSetEntry; "Dimension Set ID") { } column(DimensionValueCode_DimensionSetEntry; "Dimension Value Code") { } column(DimensionValueID_DimensionSetEntry; "Dimension Value ID") { } column(DimensionValueName_DimensionSetEntry; "Dimension Value Name") { } column(GlobalDimensionNo_DimensionSetEntry; "Global Dimension No.") { } dataitem(DimensionSetEntry2; "Dimension Set Entry") { DataItemLink = "Dimension Set ID" = DimensionSetEntry."Dimension Set ID"; column(DimensionCode_DimensionSetEntry2; "Dimension Code") { } column(DimensionName_DimensionSetEntry2; "Dimension Name") { } column(DimensionSetID_DimensionSetEntry2; "Dimension Set ID") { } column(DimensionValueCode_DimensionSetEntry2; "Dimension Value Code") { } column(DimensionValueID_DimensionSetEntry2; "Dimension Value ID") { } column(DimensionValueName_DimensionSetEntry2; "Dimension Value Name") { } column(GlobalDimensionNo_DimensionSetEntry2; "Global Dimension No.") { } dataitem(GLEntry; "G/L Entry") { DataItemLink = "Dimension Set ID" = DimensionSetEntry2."Dimension Set ID"; SqlJoinType = InnerJoin; column(Entry_No_GLEntry; "Entry No.") { } filter(DimensionSetID_GLEntry; "Dimension Set ID") { } column(Amount_GLEntry; Amount) { Method = Sum; } column(CreditAmount_GLEntry; "Credit Amount") { } column(DebitAmount_GLEntry; "Debit Amount") { } filter(G_L_Account_No_GLEntry; "G/L Account No.") { } filter(Posting_Date_GLEntry; "Posting Date") { } } } } } }
How I call the Query
local procedure GetActual(OpenPage: Boolean): Decimal var GLEntry: Record "G/L Entry"; TempGLEntry: Record "G/L Entry" temporary; GetActualByDim: Query "Get Actual By Dim."; Amount: Decimal; begin Clear(GetActualByDim); if GeneralLedgerSetup.Level_1_Dim <> '' then begin GetActualByDim.SetRange(GetActualByDim.DimensionCode_DimensionSetEntry, Rec."Dimension Code"); GetActualByDim.SetRange(GetActualByDim.DimensionValueCode_DimensionSetEntry, Rec.Code); end; if GeneralLedgerSetup.Level_2_Dim <> '' then begin GetActualByDim.SetRange(GetActualByDim.DimensionCode_DimensionSetEntry2, GeneralLedgerSetup.Level_2_Dim); GetActualByDim.Setfilter(GetActualByDim.DimensionValueCode_DimensionSetEntry2, Level2DimensionFilter); end; GetActualByDim.SetFilter(GetActualByDim.G_L_Account_No_GLEntry, GLAccountFilter); GetActualByDim.SetFilter(GetActualByDim.Amount_GLEntry, '<>%1', 0); GetActualByDim.Open(); while GetActualByDim.Read() do if GLEntry.Get(GetActualByDim.Entry_No_GLEntry) then begin TempGLEntry := GLEntry; if TempGLEntry.Insert() then Amount += GetActualByDim.Amount_GLEntry; end; if OpenPagethen Page.Run(0, TempGLEntry); exit(Amount); end;
0
Answers
-
By nav standard if you go to chart of accounts and use the flowfilters (limit totals to) you can filter by dimensions and will show you the balances.
0 -
Analysis views are made for reporting on dimensions. You should look into this. You can have them adjust on the fly or on demand.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions