Skip to Content

One question you’re very likely to encounter when reporting with Web Intelligence is “how do I find the latest something?”, whether it’s the latest employee data, last invoice, or most recent date for something.

Most people go with a mechanism whereby they return all data into a report, then identify a maximum value, and using a boolean test, hide all other rows that do not match the maximum value. This is a tried and tested mechanism that works very well, but the disadvantage to this is that you must return all data to the report before you can identify the maximum (or minimum) value you need.

The following method performs this task at the Universe / Query level using a Correlated Subquery, and so restricts the data returned by the query.

For this example, we’re using Business Objects 3.1 and we will be using the Island Resorts Marketing Universe. Our goal is identifying the latest (maximum) Invoice Date per Customer.

If we create as simple report using only the Customer and Invoice Date objects to check Customer Invoice Dates, we can see there are a few customers that have multiple Invoice Dates – “Baker” for instance.

/wp-content/uploads/2014/08/1_514409.png

(results have been sorted in a descending fashion to show the latest date first, with a break on Customer)


We want to return only the latest date, so for “Baker” this will be 19/12/2006.

To do this we need to create a Universe Filter to restrict the data. We will be generating the SQL we put into the filter via the Query Panel, which is found on the Tools menu.

/wp-content/uploads/2014/08/2_514410.png

In the top part of the Query Panel (Results), drag in the two objects we need to identify our result – the Customer and the Invoice Date.

/wp-content/uploads/2014/08/3_514411.png

In the bottom part (conditions) drag in the Invoice Date object, as this is the object we need to calculate our result by. It will prompt you to select an Operator – we’re going to select Equal To.

/wp-content/uploads/2014/08/4_514413.png

Next it will ask us to select an Operand (what is it equal to?) – we select Calculation as we’re going to Calculate a result.

/wp-content/uploads/2014/08/5_514414.png

Now it will ask us what Object we want to use in the Calculation – we want the Invoice Date.

/wp-content/uploads/2014/08/6_514454.png

Next, what function do we want in the Calculation? We want the Maximum function in order to calculate the Maximum Invoice Date.

/wp-content/uploads/2014/08/7_514455.png

As the “Define Level of Calculation” text suggests, if we want a single result we select Globally – we want a single maximum, not several.

/wp-content/uploads/2014/08/8_514456.png

We want to calculate the result for each Customer, so we select our Customer object here.

/wp-content/uploads/2014/08/9_514457.png

Finally, select All Values.

/wp-content/uploads/2014/08/10_514458.png

This will return us to the Query Panel. From here we need to copy the SQL that has been generated, so press the SQL button to show the SQL editor.

/wp-content/uploads/2014/08/11_514459.png

This shows us the SQL for the query we just generated.

/wp-content/uploads/2014/08/12_514463.png

We only want the Where part of the SQL that is generated, so copy this section (you may want  to copy the entire text to a text editor just in case, as we will be closing the query panel and the SQL will be lost).

/wp-content/uploads/2014/08/13_514464.png

Close the Query Panel and then create a new Filter object and give it a meaningful name.

/wp-content/uploads/2014/08/14_514469.png

..and copy the Where part of our SQL query into our new Filter object Where statement.

/wp-content/uploads/2014/08/15_514470.png

Save and export the universe. Now if we run our report again but this time include our new filter object, the results return only the latest Invoice Date per Customer.

/wp-content/uploads/2014/08/16_514490.png

To illustrate the difference, look at the Query Summaries without the Filter and with.

/wp-content/uploads/2014/08/17_514491.png

Without the filter, the query returns 342 rows.

/wp-content/uploads/2014/08/18_514492.png

With the Filter, the query returns only 39 rows.

Obviously this is just a brief introduction to this subject. We’ve looked at how to calculate a Maximum, but other calculations can be accommodated too. Experiment with the options yourself

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply