Blog Post

Community Blog
3 MIN READ

"Top N" reports - no code required!

JackLacava's avatar
JackLacava
Honored Contributor
6 months ago

It has been a quiet Tuesday morning at Badabing Ltd. Had some decent coffee, checked all reports went out last night, and basked in the glory of a sea of green "OK" calculation statuses. As you ponder whether to dig into your third cannoli of the day, a voice booms across the office: "Hey Joey! Joey! Camhear.... Y'know the top-5-products report you sent out last night, yea? The one they built for us back in 2021, them wunderkids from the City? Boss wants to make it top-10, and to bring extra columns in it. Oh, and make it a bit different - all our reports kinda look the same, he gets confused, y'know, and we don't want him confused - he might whack the wrong thing, 'nowwattamean?"

"... Sure, am on it."

This is gonna be painful. That report uses some custom Dashboard DataSet and Member List, written by someone trying to earn their fee by looking clever. You kinda know your VB from your C#, but changing this pile of hacks looks daunting. Y'know what, fuggedaboutit - you're just going to scrap it and rebuild the report without any code!

The data - Cube View + Data Adapter

First, we'll have to find the data we need. Cube Views are great for that! So you quickly build a simple CV with all your product sales data.

 CVs don't allow for sorting by value, and without code they can only be formatted in a standard way for PDF output. That's alright; we have Dashboard Components that are much more customizable! To bring our CV data to such components, we will simply build a basic Data Adapter (on the Workspaces page for v.7.3+, or Dashboards page for older versions).

Interactive Report - BiViewer

Alright, so we got the data, how do we display it? BiViewer is the obvious choice for interactive reporting. It looks nice and it's so easy to configure. First we attach the DataAdapter and save:

Then we switch to BI Designer, create a Grid, drag and drop a few columns and boom, it's done.

Ok, but now we have too many products, and not sorted. How do we fix that? Easy:

And it's done! We can now trivally add some bells and whistles: extra columns, custom formatting, and so on.

Print-perfect Reporting - Report Component

Bi Viewer is great, but the Boss is old-fashioned: he likes paper that can be stored away, just in case something happens, y'know? How do we deal with this? Easy: with the Report Component.

We create the component and again attach the very same adapter:

We then switch to the Report Designer, and we drag and drop our fields in the Detail Band:

Next, we need to sort our records, using the Group And Sort toolview:

We select our Amount field from the Add a Sort menu

Then set it to sort in Descending order

At this point, data in the report would be sorted correctly, but it would still show too many products rather than the top 10. To cut the number of records displayed, we have to open the properties of our Report object, and select the gears icon:

We then expand "Report Print Options" to find the Detail Count value. By default it's set to zero, which means all records will be displayed. By changing that we can limit our output to the first 10 records:

(If you're wondering what the difference is between that and the "at Design Time" version: "Design Time" is when you look at the Preview tab in the Report Designer. If you know you have a lot of records and you're just testing some layout tweaks, you can set this to a low number to speed up preview generation. Like for the other version, a zero means it's disabled and all records will be displayed.)

And this is our output:

Now we'll have a bit of fun with graphics, formatting, and so on, making our report stand out. Hey - all this was so fast, there are still some cannoli left!

Updated 8 months ago
Version 1.0
No CommentsBe the first to comment