Home > Articles

This chapter is from the book

Avoiding Query Macros

In class, we teach students that query macros can be written to take advantage of the IBM Cognos BI capability to dynamically change the report queries at runtime. Query macros can be built to integrate information about the report consumer or to enhance the queries that are written. Unfortunately, the query macros are not easy to master because the documentation exists only in the IBM Cognos Framework Manager documentation. In our example, we will show how the solution to the common business problem can be resolved without resorting to the use of query macros.

The sales team wants to be able to quickly analyze how each retailer region is performing according to product quantities sold, revenue produced, and gross profit achieved. The sales team would like to be able to filter the results in one of three ways: by selected date, by selected order method, or by selected employee.

The team would like one report where they can select the type of filter and the value to include for the filter and see the results in a crosstab so that they can quickly compare the numbers between the products and the regions. The final prompt result we are trying to achieve should look similar to Figure 1.8.

Figure 1.8

Figure 1.8 Main prompt page

After the prompt is selected, the report will run with a completely different filter option, and in case the prompt triggers another parameter, a new corresponding prompt will show up for the user to make the final selection.

Different second-page prompts are illustrated in Figures 1.9, 1.10, and 1.11.

Figure 1.9

Figure 1.9 Second conditional prompt page: Date Range

Figure 1.10

Figure 1.10 Second conditional prompt page: Order Method

Figure 1.11

Figure 1.11 Second conditional prompt page: Employee

Figure 1.12 illustrates the final report that is desired (we are assuming an Order method prompt selection and a specific order method selection).

Figure 1.12

Figure 1.12 Final report

Design

We have discovered that macro code syntax help is not readily available for IBM Cognos Report Studio developers. It is covered extensively in IBM Cognos Framework Manager training and materials but not in IBM Cognos Report Studio user guides.

We have to change the syntax of the filter expression depending on what the user selects in the prompt at runtime.

The reason we cannot just pass the filter expression as a parameter value is that it will be treated by the report engine as a text value and not as “code” that has to be used as a filter expression.

For this reason, the expression is captured in a prompt macro function. However, writing the macro function or finding out what the correct syntax is may be difficult for novice report developers who may not have access to the IBM Cognos Framework Manager developers who can help them.

The solution we are proposing in this example will completely avoid the use of macros, and it will be easy for business users to understand and replicate.

Our sample report will be a crosstab report that will be filtered in one of the three ways that users select at runtime. The options will be by date range, by order method, or by sales rep.

Step-by-Step

We will start with a simple crosstab template.

Step 1: Start the Report

  1. Launch Report Studio and select the GO Data Warehouse (query) package.
  2. Click on Create new option.
  3. Select the Crosstab report template and click OK.

    We will be using the Sales (query) namespace inside the Sales and Marketing (query) folder (same as for the previous example).

Step 2: Set Up the Crosstab and the Query

When it comes to creating reports, there are two approaches. As in this example, you can build the query and the report layout at the same time. Our first example provides an approach where you can build the query first and then create the report layout.

  1. From the Source tab of the Insertable Objects pane, drag the following query items into the Crosstab:
    • Product Line from the Products query subject to the Rows drop zone
    • Quantity, Revenue, and Gross profit from the Sales fact query subject to the Columns drop zone
  2. In the Explorer bar, mouse over the Query Explorer and select Query1.
  3. From the Toolbox tab of the Insertable Objects pane, drag the Filter object into the Detail Filters pane.

    The Detail Filters Expression box pops up.

  4. Create the following filter expression:
    CASE ?choice?
    WHEN 1 THEN ([Sales (query)].[Time].[Date] in_range ?Date?)
    WHEN 2 THEN ([Sales (query)].[Order method].[Order method code]
    = ?OrderMethod?)
    ELSE ([Sales (query)].[Employee by region].[Employee key] =
    ?Employee?)
    END
  5. Validate the expression, choosing any prompt values, and click OK to close the dialog box.
  6. To return to the page design, mouse over the Page Explorer tab and select Page1.
  7. Click on any whitespace in the page body to select it and click on the Center button on the toolbar.
  8. Click on the report title text to select it, and change the Source Type property from Text to Report Expression.
  9. Double-click on the Report Expression property box.

    The Report Expression dialog box opens.

  10. Create the following expression:
    'Product Line Summary for ' + ParamDisplayValue('choice')
  11. Validate the expression, choosing any prompt values, and click OK.

    Our crosstab report setup is complete at this point.

Step 3: Set Up the First Prompt Page

  1. Mouse over Page Explorer and select the Prompt Pages folder.
  2. Drag a Page object from the Insertable Objects pane into the Prompt Pages pane.

    This will be Prompt Page1.

  3. Double-click on PromptPage1 to enter page design mode.
  4. Change the page title text to this:
    Prompt Page 1 - Select Filter Type
  5. From the Toolbox tab of the Insertable Objects pane, drag a Value Prompt object into the page body of the prompt page.

    The Prompt Wizard dialog box opens.

  6. Click on the Use existing parameter radio button, and from the drop-down menu, select the choice parameter.
  7. Click on the Finish button to close the Prompt Wizard dialog box.
  8. Click on the newly created value prompt to select it.
  9. Double-click the Static Choices property in the Properties pane.

    The Static Choices dialog box is displayed.

  10. Click on the Add button in the lower-left corner of the Static Choices dialog box.

    The Edit dialog box opens.

  11. Type in the value 1 in the Use property text box and type Filter by date range in the Display property text box.
  12. Repeat the preceding step to add two more static values:
    • Use: 2 and Display: Filter by order method
    • Use: 3 and Display: Filter by sales rep

    Your Static Choices dialog box should look similar to Figure 1.13.

    Figure 1.13

    Figure 1.13 Static Choices dialog box

  13. Click OK to close the Static Choices dialog box.
  14. While you still have the value prompt selected, change the Select UI property to Radio button group.
  15. Change the Auto-Submit property to Yes.
  16. Click on any whitespace in the prompt page body to select it and click on the Center button on the Toolbar.
  17. Click on the page footer (which has all the prompt buttons) and Delete it.

    We do not need the buttons because the prompt control we built on this page has the auto-submit property turned on, and it will submit the selections as soon as the user clicks on one of the radio buttons.

    We have completed the first prompt page.

Step 4: Set Up the Second Prompt Page

The prompt controls shown on the second prompt page will depend on the selections made in the first page.

  1. Mouse over Page Explorer and select the

    Prompt Pages folder.

  2. Drag a Page object from the Insertable Objects pane into the Prompt Pages pane below Prompt Page1.

    This will be Prompt Page2.

  3. Double-click on PromptPage2 to enter prompt page design mode.
  4. Change the page title text to this:
    Prompt Page 2 - Select the Filter Value
  5. From the Toolbox tab of the Insertable Objects pane, drag the Conditional Blocks object into the prompt page body.
  6. Click on the Conditional Blocks object to select it.
  7. Double-click on the Block Variable property in the Properties pane.

    The Block Variable dialog box opens.

  8. From the Variable drop-down menu, select the <New string variable> option.

    The New Variable dialog box opens.

  9. Make the Name of the new variable choice.
  10. Click on the Add button in the lower-left corner of the dialog box.

    The Add dialog box opens.

  11. Enter the value 1 and click OK.

    We will repeat the previous steps to add two more values: 2 and 3.

  12. Click on the Add button again in the lower-left corner of the dialog box.

    The Add dialog box opens.

  13. Enter the value 2 and click OK.
  14. Click on the Add button one more time in the lower-left corner of the dialog box.

    The Add dialog box opens.

  15. Enter the value 3 and click OK.

    Your New Variable dialog box will look similar to Figure 1.14.

    Figure 1.14

    Figure 1.14 New Variable dialog box

  16. Click OK.

    The Report Expression dialog box window opens.

  17. Create the following expression:
    ParamValue('choice')
  18. Validate the expression and click OK twice to close the Report Expression and Variable dialog boxes.
  19. Change the Current Block property value from (Other) to 1.

    We will now design the prompt for when the users select a date range filter type.

  20. From the Toolbox tab of the Insertable Objects pane, drag a Date prompt into the conditional block.

    The Prompt Wizard dialog box is displayed.

  21. Click on the Use existing parameter radio button, and from the drop-down menu, select the Date parameter.
  22. Click the Finish button to close the Prompt Wizard dialog box.
  23. Click on the newly inserted Date prompt control to select it.
  24. Change the Multi-Select property to No.
  25. Click on the background of the Conditional Block to select it.
  26. Change the Current Block property to 2.

    We will now design the prompt for when the users select an order method filter type.

  27. From the Toolbox tab of the Insertable Objects pane, drag a Value prompt into the conditional block.

    The Prompt Wizard dialog box opens.

  28. Select the Use existing parameter radio button and from the drop-down menu select the OrderMethod parameter.
  29. Click the Next button.
  30. Change the Name property from Query2 to OrderMethodPrompt.
  31. Set the Values to display value to [Sales (query)].[Order method].[Order method type].
  32. Click on the Finish button to close the Prompt Wizard dialog box.
  33. Click on the background of the Conditional Block to select it.
  34. Change the Current Block property to 3.

    We will now design the prompt for when the users select an employee filter type.

  35. From the Toolbox tab of the Insertable Objects pane, drag a Value prompt into the conditional block.

    The Prompt Wizard dialog box opens.

  36. Click on the Use existing parameter radio button, and from the drop-down menu, select Employee parameter.
  37. Click on the Next button.
  38. Change the Name property from Query2 to EmployeePrompt.
  39. Set the Values to display value to [Sales (query)].[Employee by region].[Employee name].
  40. Click on the Finish button to close the Prompt Wizard dialog box.

    Our second prompt page design is finished at this point. It can be enhanced by the addition of text boxes for additional instructions to the users, or prompt controls can be modified to have a different UI.

You can now test the report prompt page flow.

Step 5: Adjust the Report Title to Show the Selected Prompt Value

The objective is to dynamically display the prompt selections that the user selected at runtime.

  1. Mouse over Page Explorer and select the Page1 object.
  2. From the Toolbox tab of the Insertable Objects pane, drag the Conditional Blocks object into the page header area below the report title block.

    We will reuse the variable we created for the purposes of the second prompt page.

  3. Click on the Conditional Block object we have just inserted, and double-click on the Block Variable property in the Properties pane.

    The Block Variable dialog box opens.

  4. From the Value drop-down menu, select the choice variable that was created during the second prompt page design.
  5. Click OK to close the Block Variable dialog box.
  6. Change the Conditional Block property value from (Other) to 1.
  7. From the Toolbox tab of the Insertable Objects pane, drag a Layout Calculation object into the Conditional Block.

    The Report Expression dialog box opens.

  8. Click on the Parameters tab of the Available Components section of the dialog box.
  9. Drag the Date parameter into the Expression Definition area.
  10. Validate the expression and click OK to close the Report Expression dialog box.
  11. From the Toolbar, click the Center button to center the parameter expression in the report title area.
  12. Change the Current Block property value to 2.
  13. From the Toolbox tab of the Insertable Objects pane, drag a Layout Calculation object into the Conditional Block.

    The Report Expression dialog box opens.

  14. Click on the Parameters tab of the Available Components section of the dialog box.
  15. Drag the Order Method parameter into the Expression Definition area.
  16. Validate the expression and click OK to close the Report Expression dialog box.
  17. From the Toolbar, click the Center button to center the parameter expression in the report title area.
  18. Change the Current Block property value to 3.
  19. From the Toolbox tab of the Insertable Objects pane, drag a Layout Calculation object into the Conditional Block.

    The Report Expression dialog box opens.

  20. Click on the Parameters tab of the Available Components section of the dialog box.
  21. Drag the Employee parameter into the Expression Definition area.
  22. Validate the expression and click OK to close the Report Expression dialog box.
  23. From the toolbar, click the Center button to center the parameter expression in the report title area.

Our report design is completed for this example.

We have achieved the desired result by using a conditional block in a second prompt page, which will show different second prompt options depending on the selections made on the first prompt page.

Furthermore, we have integrated the dynamic filter logic without the use of macro functions in order to demonstrate that novice report developers can be quite capable of creating very complex dynamic prompts and filter reports without advanced macro programming knowledge.

Finally, we have shown you how to dynamically control what will be shown in the title of the report based on the user’s selections during the prompt process.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020