Na2009 enus devii_07

14
Chapter 7: Statistics 7-1 CHAPTER 7: STATISTICS Objectives The objectives are: Create a page that calculates price sums efficiently. Make the page available from the Seminar pages. Use FlowFilters to easily calculate statistics for different time periods. Introduction In this chapter statistics are added to the Seminar Management module. Seminar managers at CRONUS International Training Academy require immediate and flexible financial reporting. Microsoft Dynamics NAV 2009 can meet this business need through the use of FlowFilters and FlowFields. Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Transcript of Na2009 enus devii_07

Page 1: Na2009 enus devii_07

Chapter 7: Statistics

7-1

CHAPTER 7: STATISTICS Objectives

The objectives are:

• Create a page that calculates price sums efficiently. • Make the page available from the Seminar pages. • Use FlowFilters to easily calculate statistics for different time

periods.

Introduction In this chapter statistics are added to the Seminar Management module. Seminar managers at CRONUS International Training Academy require immediate and flexible financial reporting. Microsoft Dynamics NAV 2009 can meet this business need through the use of FlowFilters and FlowFields.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 2: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-2

Prerequisite Information FlowFilters are useful for limiting calculations so that they include only the values in a column that have specific properties. For example, on the Seminar Statistics page, users may want to sum the total price of a seminar four different times, for four different time periods (such as week, month, current year, and prior year). This is possible if the application is designed to take advantage of SumIndexField Technology (SIFT) using FlowFilter fields in connection with the FlowFields. FlowFilters are used to determine how much information the system includes when it calculates the contents of FlowFields.

Using FlowFilters and FlowFields

A FlowField is defined by setting the FieldClass property of the field to FlowField. The functionality of the FlowField is thereby defined by the value of the CalcFormula property of that field. The CalcFormula can include filter values which are based on constant and/or variable parameters. A FlowFilter is a specific type of filter field that is defined in the same table that has the FlowField to which it applies. Thus, FlowFilters can be applied to the source tables on which FlowFields are based.

To implement a statistics page using the FlowFields and FlowFilter fields in a master table, look at Table 18 Customer and Page 151 Customer Statistics. The columns of the Customer Statistics Sales FastTab show the Sales (LCY) for four different time periods:

• This Period • This Year • Last Year • To Date

The data shown in these fields is generated by means of a FlowField, Sales (LCY), and a number of FlowFilters in the Customer table. The CalcFormula shown in the Sales (LCY) field properties uses a number of FlowFilters, but to simplify, just consider the Date Filter.

In the OnAfterGetRecord trigger of the Customer Statistics page, the Date Filter is set for each of the desired time periods using the Date Filter-Calc codeunit. The CALCFIELDS function is then used for each Date Filter to calculate a value for the Sales (LCY). Use similar logic when creating the Seminar Statistics page.

For more information on SIFT, FlowFields, and FlowFilters, refer to the Microsoft Dynamics NAV 2009 Developer and IT Pro Help.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 3: Na2009 enus devii_07

Chapter 7: Statistics

7-3

Seminar Statistics The purpose of the seminar statistics feature is to allow the user to quickly and easily get an overview of the price statistics for a specific seminar.

Solution Analysis

FlowFields and FlowFilters can be used on the customer solution to provide statistics described in the functional requirements in Chapter 1, Business Case Diagnosis and Analysis.

The client's functional requirements provide the following regarding statistical requirements:

"Statistics for different time periods, such as: for a month, for last year, for this year, and up to the current date."

This description indicates that the client wants to be able to open a Statistics page from a Seminar page. This page calculates the statistics for the total price and shows it for the four time periods listed.

Seminar managers are to have access to the seminar statistics from a Seminar Detail page. This page calculates the total price statistics for the seminar for the time periods indicated in the function requirements.

Solution Design

The Seminar Statistics page is to be accessible from the Related Information menu on the Seminar Card and Seminar List pages. It automatically calculates the statistics for the selected seminar using the information from the Seminar Ledger Entry.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 4: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-4

The Seminar Statistics page displays statistical information for one seminar, as shown in the following figure.

FIGURE 7.1 THE SEMINAR STATISTICS PAGE (123456714)

Seminar Card (Page 123456700): The Seminar menu selection on the Related Information button on this page is modified to include a new menu item for seminar statistics.

Seminar List (Page 123456701): The Seminar menu selection on the Related Information button on this page is modified to include a new menu item for seminar statistics.

The solution requires that FlowFields and FlowFilters are added to the Seminar table (123456700). Also, a key of Seminar No., Posting Date, Charge Type, Chargeable is added to the Seminar Ledger Entry table 123456732.

The Total Price, Total Price (Chargeable) and Total Price (Not Chargeable) in the Seminar table is calculated using values from the Seminar Ledger Entry, for four different time periods. An array of four dimensions is used to store the totals for each of these three prices. The standard DateFilter-Calc codeunit is used to calculate date filters for the time periods. With the date filters, the Seminar table can be filtered and used to calculate the price fields to be shown on the page for each of the four time periods.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 5: Na2009 enus devii_07

Chapter 7: Statistics

7-5

Lab 7.1 - Creating FlowFields for Sums Scenario

FlowFields are needed to support the planned Statistics page.

Challenge Yourself!

Implement FlowFields for sums in the Seminar solution.

Step by Step

Follow these steps to implement FlowFields for sums in this solution

1. Add a secondary key of Seminar No., Posting Date, Charge Type, Chargeable to the Seminar Ledger Entry table (1123456732). Set the property for the key so that the Total Price field is the sum index field.

2. Add fields to the Seminar table (123456700) as shown in the following table.

No. Field Name Type Length Comment

20 Date Filter Date FlowFilter

21 Charge Type Filter

Option FlowFilter; Options: Instructor, Room, Participant, Charge

25 Total Price Decimal FlowField; refer to step 3 below for the CalcFormula. Must not be editable. AutoFormatType=1

26 Total Price (Not Chargeable)

Decimal FlowField; refer to step 4 below for the CalcFormula. Must not be editable. AutoFormatType=1

27 Total Price (Chargeable)

Decimal FlowField; refer to step 5 below for the CalcFormula. Must not be editable. AutoFormatType=1

3. Set the CalcFormula for the Total Price field so that it calculates the

sum of the Total Price field on the Seminar Ledger Entry table for the records where the Seminar No. corresponds to the No. field, where the Posting Date corresponds to the Date Filter, and where the Charge Type corresponds to the Charge Type Filter.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 6: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-6

4. Set the CalcFormula for the Total Price (Not Chargeable) field so that it calculates the sum of the Total Price field on the Seminar Ledger Entry table for the records where the Seminar No. corresponds to the No. field, where the Posting Date corresponds to the Date Filter, where the Charge Type corresponds to the Charge Type Filter, and where the records are not Chargeable.

5. Set the CalcFormula for the Total Price (Chargeable) field so that it calculates the sum of the Total Price field on the Seminar Ledger Entry table for the records where the Seminar No. corresponds to the No. field, where the Posting Date corresponds to the Date Filter, where the Charge Type corresponds to the Charge Type Filter, and where the records are Chargeable.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 7: Na2009 enus devii_07

Chapter 7: Statistics

7-7

Lab 7.2 - Creating the Seminar Statistics Page Scenario

A Seminar Statistics page is required.

Challenge Yourself!

Following the approach used for other statistics pages and using the table changes just completed, create a Seminar Statistics page and make it accessible from the Seminar Card and List pages.

Step by Step

Follow these steps to implement the statistics page:

1. Create the Seminar Statistics page (123456714), based on the Seminar table. A statistics page has a PageType of Card, and has the LinksAllowed property set to No. Do not add any controls to this page yet.

2. Define the following global variables for the page:

Name DataType Subtype Length

DateFilterCalc Codeunit DateFilter-Calc

SeminarDateFilter Text 30

SeminarDateName Text 30

CurrentDate Date

TotalPrice Decimal

TotalPriceNotChargeable Decimal

TotalPriceChargeable Decimal

I Integer

3. Set the Dimensions property for all the variables except

DateFilterCalc, CurrentDate, and I so that each variable is an array of four dimensions.

4. Set the property for the page so that it is not editable. 5. Enter code in the appropriate trigger so that after the page gets the

record, the program performs the following tasks: o Filters the table to the selected seminar.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 8: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-8

o If the CurrentDate is not the work date, the program sets the CurrentDate variable to the work date. - Runs the CreateAccountingPeriodFilter function of the

DateFilter-Calc codeunit with parameters of the first dimensions of the SeminarDateFilter and SeminarDateName, the CurrentDate, and 0 (zero).

- Runs the CreateFiscalYearFilter function of the DateFilter-Calc codeunit with parameters of the second dimensions of the SeminarDateFilter and SeminarDateName, the CurrentDate, and 0.

- Then runs the CreateFiscalYearFilter function of the DateFilter-Calc codeunit with parameters of the third dimensions of the SeminarDateFilter and SeminarDateName, the CurrentDate, and the value -1.

HINT: There is similar code on the Customer Statistics page.

o For each of the dimensions, filters the table to records where the Date Filter corresponds to the value in the appropriate dimension of the SeminarDateFilter and calculates the Total Price, Total Price (Not Chargeable), and Total Price (Chargeable) fields.

o Sets the value for the appropriate dimension of the TotalPrice, TotalPriceNotChargeable, and TotalPriceChargeable to the values in the corresponding fields.

o Filters the table to those records where the Date Filter is before the CurrentDate.

6. Add a ContentArea Container to the page, and add an indented Group with label General to the ContentArea.

7. Add a Group with no label and subtype FixedLayout, which is the frame for the statistics area of this page. The values will be populated by defining columns for all four (4) dimensions.

8. Add a Group labeled This Period. Indented underneath this group, add an unlabeled field for SeminarDateName[1], a field labeled Total Price for TotalPrice[1], a field labeled Total Price (Not Chargeable) for TotalPriceNotChareable[1], and a field labeled Total Price (Chargeable) for TotalPriceChargeable[1].

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 9: Na2009 enus devii_07

Chapter 7: Statistics

7-9

9. Repeat step 8 for three more groups labeled This Year, Last Year, and To Date. Be sure each of these three groups has appropriately increasing dimension values.

FIGURE 7.2 SEMINAR STATISTICS PAGE (123456714) IN PAGE DESIGNER

10. The last steps are to make the page accessible from the two seminar pages. Add the selections described in the table of the Related Information menu of the Seminar Card page (123456700) between the Comments and the Extended Texts menu items.

Additional Seminar menu button action items:

Options Comment

Ledger E&ntries (Ctrl+Shift+N)

Opens page 123456721 Seminar Ledger Entries for the selected Seminar. Set the Image property to CustomerLedger.

<Separator>

&Statistics (Ctrl+Shift+J)

Opens page 123456714 Seminar Statistics for the selected seminar. Set the Image property to Statistics.

<Separator>

11. Add the same menu selections to the Seminar List page

(123456701) that are described in step 10.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 10: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-10

Solution Testing

To test the statistics page, it is necessary to have entries in the Seminar Ledger Entry table with the related posted seminar registrations. Follow these steps to verify the solution implementation:

1. Open the Seminar Card and view a seminar that has some posted registrations. Verify that the seminar has ledger entries by selecting seminar, clicking entries, and then selecting ledger entries from the Seminar Card.

2. Select seminar, and then click statistics to open the Seminar Statistics window.

3. Verify that the totals shown are correct for the different rows and columns. It may be convenient to apply a table filter to the Seminar Ledger Entries window and compare the results with the amounts shown in the Seminar Statistics window.

Summary This chapter focused on creating a statistics page for seminars that sums the total price in four different time periods. This statistics page is made available from the seminar pages' Related Information menu. This functionality is added though the use of FlowFields and FlowFilters, which use SIFT technology to provide filtered statistics quickly and easily.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 11: Na2009 enus devii_07

Chapter 7: Statistics

7-11

Test Your Knowledge

1. What is the purpose of a FlowFilter field?

2. How are FlowFilters used in calculations of FlowFields?

3. What are the advantages of using FlowFields to make calculations?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 12: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-12

4. What is the Microsoft Dynamics® NAV standard shortcut for opening a Statistics page?

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 13: Na2009 enus devii_07

Chapter 7: Statistics

7-13

Quick Interaction: Lessons Learned Take a moment and write down three key points you have learned from this chapter

1.

2.

3.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 14: Na2009 enus devii_07

C/SIDE Solution Development in Microsoft Dynamics® NAV 2009

7-14

Solutions Test Your Knowledge

1. What is the purpose of a FlowFilter field?

MODEL ANSWER:

A FlowFilter is a special type of filter field that is defined in the same table that has the FlowField to which it applies. FlowFilters can be included in the CalcFormula of the FlowField to allow user defined filters to be applied in the calculation of the FlowField. When the user sets a filter in a FlowFilter, the system includes the FlowFilter value as a filtering constraint when calculating the contents of related FlowFields.

2. How are FlowFilters used in calculations of FlowFields?

MODEL ANSWER:

FlowFilters are set as filter values in the CalcFormula of FlowFields, and are used to limit the information that is retrieved when the system calculates the value of a FlowField.

3. What are the advantages of using FlowFields to make calculations?

MODEL ANSWER:

The advantages of using FlowFields are: a) to make it easier to develop and use fields with calculated values, and b) to make such calculations process faster. Calculating FlowFields takes just a few lines of C/AL code, because the filters and parameters are defined in the field's CalcFormula property. Writing code to calculate those values directly from their source tables takes considerably more effort to develop and in some cases, may take considerably more processing of data to calculate.

4. What is the Microsoft Dynamics® NAV standard shortcut for opening a Statistics page?

MODEL ANSWER:

The standard shortcut key for opening a Statistics page is Ctrl+Shift+J.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement