Professional Documents
Culture Documents
Complex Queries in Business Objects
Complex Queries in Business Objects
BusinessObjects
2 Complex Queries in BusinessObjects
Here are some reminders of good data stewardship to help you carry out your
responsibility:
• Do not share your passwords or store them in an unsecured manner. Do not leave
your workstation unattended while logged on to administrative information
systems. You are responsible for any activity that occurs using your logon id.
• Do not share confidential and sensitive information with anyone, including
colleagues, unless there is a business reason.
• Retrieve printed reports quickly, and do not leave the reports lying around in plain
view.
• Secure reports containing confidential and sensitive information (e.g., FERPA, EEO
or HIPAA protected data).
• When disposing of reports containing confidential or sensitive information, shred
the documents in a timely manner.
Table of Contents
Appropriate Use And Security Of Confidential And Sensitive Information............................................ 2
About this Course........................................................................................................................................ 5
Objective............................................................................................................................................ 5
Instructor Led Course ........................................................................................................................ 5
Training Data ..................................................................................................................................... 5
Practice.............................................................................................................................................. 5
Files ................................................................................................................................................... 5
Demos ............................................................................................................................................... 5
Chapter 1..................................................................................................................................................... 7
Formulas and Variables ....................................................................................................................... 7
Formulas............................................................................................................................................ 7
Resetting the RunningSum ...............................................................................................................10
Variables .............................................................................................................................................10
Creating a Variable ...........................................................................................................................10
Exercise 1 – Formulas and Variables ...............................................................................................13
Chapter 2....................................................................................................................................................15
Grouping Values .................................................................................................................................15
Using the Group Option ....................................................................................................................15
Using the Groups ..............................................................................................................................18
Exercise 2 – Grouping Values ..........................................................................................................19
Chapter 3....................................................................................................................................................21
Grouping Measure Objects .................................................................................................................21
Sales Grouping .................................................................................................................................21
Exercise 3 – Grouping Measure Objects ..........................................................................................24
Chapter 4....................................................................................................................................................25
Calculation Contexts ...........................................................................................................................25
Input and Output Contexts ................................................................................................................25
Calculation Context Operators ..........................................................................................................25
Calculation Context Keywords ..........................................................................................................26
Calculation Context Example ............................................................................................................26
Viewing Calculation Contexts ...........................................................................................................27
Changing the Calculation Context.....................................................................................................28
Exercise 4 – Calculation Contexts ....................................................................................................29
Chapter 5....................................................................................................................................................31
Subqueries ..........................................................................................................................................31
Multiple Data Providers.....................................................................................................................32
Verifying the Results .........................................................................................................................33
Managing Data Providers .................................................................................................................35
Renaming Data Providers.................................................................................................................35
Purging vs Deleting a Data Provider .................................................................................................36
Exercise 5 – Subqueries ...................................................................................................................38
Chapter 6....................................................................................................................................................39
Using Personal Data Files...................................................................................................................39
File Types Available..........................................................................................................................39
Options with .XLS Files.....................................................................................................................39
Creating a Report from an XLS File ..................................................................................................39
Options with Text Files......................................................................................................................41
Create a table from a .CSV personal data file...................................................................................41
Create a Second Data Provider ........................................................................................................43
Exercise 6 – Using Personal Data Files............................................................................................46
Chapter 7....................................................................................................................................................47
Combining Data from Different Data Providers ...................................................................................47
Linking Data Providers......................................................................................................................47
Incompatible Objects ........................................................................................................................48
Combining Data in the Table ............................................................................................................49
Exercise 7 – Combining Data from Different Sources.......................................................................51
Appendix A –Review Answers....................................................................................................................53
4 Complex Queries in BusinessObjects
Appendix B.................................................................................................................................................55
User Objects .......................................................................................................................................55
User Objects .....................................................................................................................................55
Creating a User Object .....................................................................................................................56
Using a User Object..........................................................................................................................59
Removing a User Object...................................................................................................................60
Appendix C – Combined Queries ...............................................................................................................61
Combined Queries............................................................................................................................61
Restrictions .......................................................................................................................................61
Building a Combined Query ..............................................................................................................61
Appendix D –Using an XML Data Provider ................................................................................................63
Appendix E – ASCII character codes .........................................................................................................67
Complex Queries in BusinessObjects 5
Training Data
Two generic universe/databases are used in the course. The eFashion universe is used
for all the examples. This universe is very small and easy to use. The EDW R&A
Training universe is used for all the exercises. While this is still generic data, it is
more like the production universes. The data was used as test data for Recruiting and
Admissions.
Practice
To repeat the examples and exercises on your own, you can use “play” accounts which
have access to the training data. These accounts have the same access as the accounts
used during the class. The play accounts are: dsplay1, dsplay2, …, dsplay10. The
password for all these accounts is 1234.
Files
Completed versions of the examples an exercises are available in a zip file at the
following location: http://www.ds.uillinois.edu/training/complex_files.zip
Demos
For a list of demos on a variety of topics related to using the BusinessObjects editor
see: http://www.ds.uillinois.edu/how_to.asp
6 Complex Queries in BusinessObjects
Chapter 1: 7
Chapter 1
Formulas and Variables
BusinessObjects allows you to create formulas and variables to manipulate the data
after it has been retrieved from the database. You can do projections, change the
format of the data, combine objects, or anything else you can think of.
While user objects operate at the database level through the SQL query, formulas and
variables act on data that has already been retrieved and stored in a data provider.
Formulas and variables are stored in the document where they are created. They are
available to any user of the document and can be refreshed or edited.
Formulas
Formulas are unnamed, which can cause some confusion when there are many formulas
within one report or document. If a formula is changed, the previous version of the
formula is kept and the new version of the formula is added. These unused versions
should be removed to prevent them from slowing the display of the report.
Formula Rules
There is certain syntax that needs to be followed when entering a formula:
• Must begin with an equal sign (=). Without an = the formula is displayed as a
constant or text.
• Variables included in formulas must be enclosed in a less than (<) and a greater
than sign (>). For example: <Sales revenue>.
• Text included in formulas must be enclosed in double-quotes (“”).
In the next example we will use the Formula Editor to enter a formula showing the
running total of Sales Revenue from month to month.
1. Create a standard report using the e-Fashion universe.
2. Add the following objects:
Store name Month Name Sales revenue
3. Run the query.
4. Create sections for each Store name value.
5. Add a custom sort on Month Name in chronological order.
8 • Complex Queries in BusinessObjects
The Formula Editor is very similar to user object editor and the variable editor,
except the Formula Editor does not have a Definition tab. A formula remains
unnamed and so has no need for a Definition tab.
Notice that when the RunningSum() is added to the formula, the cursor is placed in
the location for the first argument.
11. Double-click Sales revenue to insert it as the first argument.
The values for the running sum of Sales revenue are added to the blank column.
10 • Complex Queries in BusinessObjects
There is no text in the column heading because the formula has no name associated
with it.
13. Double-click the column heading for the last column.
14. Enter Total.
Variables
A variable is a named formula. They can be used in the same way as variables in the
data provider. Variables are stored in the document .
Creating a Variable
Creating a variable is a very similar process to that of creating a formula. The major
difference between the two is that the Variable Editor has a Definition tab, where the
name and variable type are specified.
We will create a variable that concatenates the Address, City, State, and Zip Code
variables into one variable named Location.
1. Edit the data provider and add the following objects:
Address City State Zip Code
2. Run the query.
3. Select DataVariables….
The Variables window will appear.
4. Click the Add… button to bring up the Variable Editor.
Chapter 1: 11
; Note: The Char(13) is a carriage return character. This forces the value for City to start
on a second line.
11. Click the Close button to close the Variables dialog box.
12. Drag and drop Location to the right of the Store name.
The report should look like:
12 • Complex Queries in BusinessObjects
14. Click the Yes button to remove the sections for Location.
15. Resize the cell to handle the widest text and two lines.
16. Remove the columns for Address, City, State, and Zip Code.
The report should look like:
Chapter 1: 13
Review
1. A variable can be used in many ways that a formula cannot: True or False?
2. A formula is not sharable among different users: True or False?
Exercise
Create a report using the EDW R&A Training universe.
Objects: First Name, Middle Name, Last Name, Degree1 Name, ACT Composite
Score
Conditions: (Predefined) Springfield.
Add a variable, Full Name, which concatenates First Name, Middle Name and Last
Name. Add the Full Name variable to the table and remove First Name, Middle Name,
and Last Name.
; Note: If a student does not have a middle name, it is stored as one space. The Full Name
variable will then have three spaces between the first and last names. This is ok for this
exercise. In the next exercise you will fix the problem with the extra spaces.
Save the document as CQ Exercise 1. This will be used in the next exercise.
Completed Exercise
14 • Complex Queries in BusinessObjects
Chapter 2: 15
Chapter 2
Grouping Values
Sometimes you will want to create new variables by grouping distinct values or a range
of values of existing variables for analysis purposes. There are two methods to
accomplish this within BusinessObjects :
• Use the Group option to group values of dimension or detail objects.
• Use If…Then…Else logic to group values of any objects.
The Group option is easier to use than If…Then…Else, but it can be used only with
dimension or detail variables.
12. Enter the name Region in the Name of the Variable text box.
First, we will group the states that will go into the East region. The states will be
groups in the following categories:
East Central West
DC Colorado California
Florida Illinois
Massachusetts Texas
New York
13. Click the New button to create a new group.
14. Enter East to rename the group.
15. While holding down the CTRL key, click on each state that will be included in the
East region,
16. Click the Add button to add them to the East folder.
Chapter 2: 17
; Note: Groups can also be created by selecting values within a column and then clicking
the Group Values button in the Report toolbar.
Review
1. The Group function works only with which Object types?
Exercise
Create a report using the EDW R&A Training universe.
Objects: Last Name, First Name, Decision Desc
Conditions: (Predefined) Chicago
Create a variable named Attending with the values of Yes, No, and Unknown
according to the values of Decision Desc as shown below.
Yes No Unknown
Admit Admission Rescinded Wait List
Admit – Applicant Accepts Applicant Rejects Offer
Admit – Limited Status Deny
Admit/Accept Limited Status SI/GPA too low for transfer
Applicant Accepts Offer
Completed Exercise
20 • Complex Queries in BusinessObjects
Chapter 3: 21
Chapter 3
Grouping Measure Objects
When possible, it’s easier to use the Group option discussed above to group values.
But, the group option is not available for measure objects. So, for measure objects it’s
necessary to create a new variable and use If…Then…Else code in its formula.
Sales Grouping
We will add a column indicating whether the sales are Low, Medium or High based on
the following:
Low: $0 – $999,9999
Medium: $1,000,000 - $1,499,999
High: $1,500,000 and above
1. Right-click in the Report Manager on an existing variable.
2. Select New Variable… from the pop-up menu.
The Variable Editor window will appear.
22 • Complex Queries in BusinessObjects
The If statement will continue through the conditions until it finds a condition that
is true. So, if the value for Sales revenue is not less than 1 million it will continue
to the next condition and check if the Sales revenue value is less than 1.5 million. If
both conditions are false it will continue to the Else, which always “true”, and
assign the value “High”.
6. Click OK.
The Revenue Group variable should appear in the Variables list.
Chapter 3: 23
7. Add the Revenue Group as a new column to the right of Sales revenue.
Your report should now look like:
Review
1. To group Measure Objects you must use If…Then…Else code: True or False?
Exercises
Open the CQ Exercise 1 document.
1. Add a variable named ACT Group with values based on the ACT Composite Score
as follows:
Good < 25
Better < 30
Best >= 30
2. Edit the formula for the Full Name variable. Remove the extra spaces if the Middle
Name is equal to a space.
Save the changes as CQ Exercise 3.
Completed Exercise
Chapter 4: 25
Chapter 4
Calculation Contexts
By default, BusinessObjects determines the result of a measure based on the dimensions
in the part of the report in which the measure is inserted. These sets of dimensions are
called calculation contexts.
For example, the tables below all include the Sales revenue object, but the values
displayed are different due to the context of the table.
ForEach
Adds a dimension to the calculation environment.
Syntax: measure ForEach dimensions
Example: Max(<Sales revenue> ForEach <Year>)
Returns the maximum annual revenue, for example for each store in the report.
26 • Complex Queries in BusinessObjects
In
Uses a keyword to define the calculation environment (syntax 2 below), or specifies the
dimensions included in the calculation environment (syntax 1 below).
Syntax 1: measure In dimensions
Example: <Sales revenue> In (<State>,<City>)
The revenue for state and city.
The values in the cells are different because of the output context. Next we will
display the context.
The extended syntax for the three Total Sales cells are, from top down:
=Sum(<Sales revenue> In Body) In Report
=Sum(<Sales revenue> In Body) In <Year>
=Sum(<Sales revenue> In Body) In (<Year>, <State>)
4. Copy and paste the formula into the Percent of Total Sales cell directly below.
5. Change the formula to: =<Sales revenue>/Sum(<Sales revenue>) In Report.
This divides the sales for the Year/State by the sales for all state for all years. The
cell should now display 4.68%.
6. Copy and paste the formula into the Percent of Total Sales cell for the year.
This divides the sales for the Year by the sales for all state for all years. The cell
should now display 22.25%.
Review
1. The Output Context keyword for all values is ______________.
2. What are two methods for viewing Calculation Context formulas?
Exercises
Create a standard report using the EDW R&A Training universe.
Objects: Last Name, First Name, UIN, ACT Composite Score
Conditions: (Predefined) Springfield
Completed Exercise
30 • Complex Queries in BusinessObjects
Chapter 5: 31
Chapter 5
Subqueries
A subquery is a query within a query. The subquery usually returns a single column of
data which is used in a condition of the main query. The subquery uses the same data
source. Subqueries are created using operand options with a condition. Depending on
the operator used in the condition, you will see one or both operand options:
Create a subquery (ALL)
This operand compares the object with all the values returned by the subquery. For
example: Sales revenue Greater than (all items of the query 1.1).
Let’s create a report that requires a subquery. We want the stores that sold at least 100
of a particular item in the month of June, 2000. The stores must have also sold at least
1000 of these items for the year. We can’t do this with one query because there are
different time periods and different amounts for the number sold.
1. Create the following query with:
City Store name Quantity sold
2. Create the following conditions:
Year Equal to 2000
Month Equal to 6
SKU desc Equal to ‘E-Watch’
Quantity sold Greater than or equal to 100
3. Add a new condition for the Store name object.
4. Select Equal to for the operator.
5. Select Create a subquery (ANY) for the operand.
A new query tab appears, Subquery 1.1.
The subquery needs to produce the list of Store names that sold at least 1000 of
theses watches for the year 2000.
6. Add Store name in the results of the subquery.
7. Add the following conditions:
Year Equal to 2000
SKU desc Equal to ‘E-Watch’
Quantity sold Greater than or equal to 1000
32 • Complex Queries in BusinessObjects
To review:
• The Subquery 1.1 returns the list of stores that had sales of at least $1 million
in 2000.
• The main query returned in the stores that sold at least 100 E-Watches in June
2000 as long as the store was in the list produced by the subquery.
You don’t have to create a new document every time you want to see new data in a
report. You can add data providers to existing documents. This feature enables you to
combine data from different sources in the same report.
Chapter 5: 33
Document 1
A document can contain multiple data
Report 1
providers and multiple reports. Each
report can contain blocks that pull data
from one or more data providers, or
combine data from different data
Data
providers in the same block. Provider 1
Report 2
The figure to the right shows a
document with two data providers and
three reports. Report 1 has a single
table with data from Data Provider 1. Data
Report 2 has two blocks with data Provider 2
from different data providers. Report Report 3
3 has one block, which combines data
from two different data providers.
3. Select Use an existing query to build a new one from the list.
34 • Complex Queries in BusinessObjects
The second table displays the stores that sold at least 100 E-Watches in June, 2000
regardless of the sales for the year. Note there is an additional store, Colorado
Springs.
The bottom table shows the number of e-Watches sold in 2000. As you can see,
Colorado Springs did not sell at least 1000.
We will rename the data providers to make them easier to work with.
36 • Complex Queries in BusinessObjects
We don’t need the last two data providers, June Sales and 2000 Sales. We will delete
them from the document.
1. Select View Data.
2. Click the 2000 Sales data provider.
3. Click the Delete button.
4. Click Yes in the confirmation box that appears
5. Delete the June Sales data provider in the same way.
6. Click OK to close the Data Manager.
The bottom two tables will now be empty since the data providers used to create the
tables have been deleted.
Chapter 5: 37
Exercise 5 – Subqueries
Note:
• Answers to all Reviews/Exercises are provided in Appendix A.
Review
1. A subquery can use a different data source. True or False?
2. A _____________________ is the data returned by running a query.
3. Can there be multiple data providers in the same document?
Exercises
Create a table with all applicants to the Chicago campus that have applied to both the
colleges of Liberal Arts and Sciences and Business Administration. The table
should include the applicant’s UIN, First Name, and Last Name.
Save the report as CQ Exercise 5
Completed Exercise
Chapter 6: 39
Chapter 6
Using Personal Data Files
Personal data files can be used as a source for a data provider. This enables you to
access data in text files, Excel spreadsheets, dBase files, and XML files. Using
personal data files allows you to use BusinessObjects to create reports from
departmental data, or combine that data with data from the EDW.
Creating a report from a personal data file is a two-stage procedure. First you specify
the personal data file you want to use for the report and then you set the options for the
type of file selected.
Sheet Name
This option lists the worksheets in the file you selected, and lets you select the
worksheet to import.
Field Selection
This option lets you select the fields from the spreadsheet to be included in the report.
You have the following options:
• All Fields
Retrieves all the data from the worksheet.
• Range Definition
Retrieves the data from specified range of cells (e.g. A1:Z20)
• Range Name
Retrieves the data from a named range defined in the worksheet.
4. Make sure Text Files (*.asc, *.prn, *.txt, *.csv) is selected as the format.
5. Click on the Browse button.
6. Select Recall List.csv from the Complex folder.
7. Check the checkbox for First row contains column names.
8. Click on the View button.
42 • Complex Queries in BusinessObjects
The data file is read and then the Data Manager dialog box is displayed.
9. Click on the SKU variable in the Data Providers panel on the left.
10. Select the Definition tab.
11. Click on the Dimension radio button to change the SKU object’s qualification to
dimension.
12. Click on the OK button to close the Data Manager dialog box.
The data from the Recall List.csv file will be displayed in a table.
Chapter 7: 43
3. Select the Access new data in a different way option and click Begin.
4. Click the Next button to use a Universe as the data source.
44 • Complex Queries in BusinessObjects
5. Select the eFashion universe from the list and click the Finish button.
6. Select the following objects in the order shown:
Store name SKU number SKU desc Quantity sold
7. Create the following conditions:
Year equal to ‘2001’
8. Drag the SKU number object to the conditions panel to create a new condition.
9. Select In list as the operator.
The objects for the second data provider will be added to the variables list. When
there are multiple data providers in the document, it is usually better to display the
variable list divided by data provider.
15. Click the By Data Provider radio button at the bottom of the Report Manager.
Now the variables are listed by data provider.
Review
1. Can an Access database be used as personal data files?
Exercise
Create a table with the information from the csv file: Problem Applicants.csv. Add a
second table with the following data from the EDW R&A Training universe for the
applicants listed in the first table.
UIN
First Name
Last Name
City
State
Completed Exercise
Chapter 7: 47
Chapter 7
Combining Data from Different Data Providers
We will now combine data from two data providers in the same table. The source for
the first data provider is a CSV file in the userDocs folder named Recall List.csv. This
file contains the SKU numbers and associated problems of the items being recalled by
the eFashion stores.
In this example, the SKU object in the first data provider must be linked to the
corresponding object in the second data provider.
1. Open the Recall.rep document.
2. Delete the table on the left with the data from the csv file.
3. Move the remaining table to the left margin.
Incompatible Objects
There is one very important rule about combining data from different data provider in
the same table. There can only be unlinked dimension objects from one data
provider. If there are dimension objects from both data providers that you want in the
table, but these objects are not linked, they cannot be appear in the table at the same
time.
1. Click on the Problem object in the first data provider.
Notice the SKU desc and Store name objects in the second data provider are grayed
out. This means these are “incompatible objects”. The Problem object is an
unlinked dimension object. SKU desc and Store name are also unlinked dimension
objects. They cannot appear in the table at the same time. To get around this
restriction we will create a detail variable that contains the same data as Problem.
Since we want two unlinked dimension objects from the second data provider and
only one from the first data provider, it’s easier to create one variable for the
Problem object rather than two variables for SKU desc and Store name.
2. Right-click on the Problem variable in the Report Manager.
3. Select New Variable… from the pop-up menu.
4. Enter Problem desc as the name of the new variable.
5. Change the Qualification to Detail.
6. For the Associated Dimension, select SKU.
The detail variable must me associated to a linked dimension object.
Chapter 7: 49
Review
1. What has to be done to combine data from different data providers into the same
table?
2. What type of objects can be linked?
3. What are “incompatible objects”?
Exercise
Open the CQ Exercise 6.rep document. Combing the data from both data providers
into one table.
Completed Exercise
52 • Complex Queries in BusinessObjects
Appendix A: 53
Exercise 5 – Subqueries
1. A subquery can use a different data source.
False
2. A data provider is the data returned by running a query.
3. Can there be multiple data providers in the same document?
Yes
Appendix B
User Objects
It is often necessary for a report developer to add data to a report that is not present in
the universe. BusinessObjects provides three ways to add data to the report:
• User Objects
• Formulas
• Variables
They all make use of the Formula window, and so may seem similar at first. But, there
are some important differences. One major difference is that user objects are associated
with a specific universe, while formulas and variables are associated with a single
document. Also, formulas and variables are stored in the document and are available to
any user refreshing or modifying the document. User objects are stored on the author’s
hard drive and are not available to other users. Another difference is that user objects
are written in SQL code, but formulas and variables are written in BusinessObjects
code.
User Objects
A user can create objects that appear to be part of the universe. These objects will
appear in the User Objects class when the universe is displayed in the Query Panel.
The user objects can be used in reports just like any other object in the universe. The
advantage of user objects is that they don’t have to be recreated for each new
document.
User objects are personal objects that are not shared with other end-users. They are
stored in a local file in the \Universe folder. The file will have the same name as the
universe.
This is because user objects are stored locally in a user object definition file. Other
end-users, who do not have the same user object definition file, are not able to access
the user object definitions. If an end-user tries to refresh or edit a query that contains
another user’s user objects, BusinessObjects removes the objects from the query and
report.
If a user object is meant to be widely shared, then we would recommend contacting
Decision Support to inquire as to the possibility of having that user object added to the
universe.
56 • Complex Queries in BusinessObjects
Both methods display the User Object dialog box to create the formula for the user
object. We will use the Tools menu to create our user object.
We want to project next year’s revenue based on a 3% increase in sales. We will do
that by adding a user object.
4. Click ToolsUniverses….
The Universes panel will appear, showing all universes to which you have access.
Minus: includes the rows from the first query minus the rows from the
second query
Restrictions
The major restrictions in combining queries are:
• the queries must contain the same number of objects
• the objects must be of the same type (i.e. character, date, number)
• there can be up to eight queries in a combined query
• when using MINUS, the second query is subtracted from the first
7. Select Minus.
8. Run the query.
A table should appear with the two rows, Samples and Skirts, that are in the query
results for 2001 but not in the results for 2000.
Appendix C: 63
Some XML elements do not contain data; they act as a container for other elements.
DATA_RECORD is an example of such an element in this file. It is not meaningful
to include such elements in a report.
9. Uncheck the Audience and Notes fields to not include them.
10. Click the Save button.
The Save XML Filter As dialog box is displayed.