|
Re: Running Count Distinct [message #557622 is a reply to message #557563] |
Wed, 08 September 2010 11:10 |
|
I don't see any straightforward way to do it unless you guarantee that your dataset is ordered on the field that you want the running count of. Otherwise on each row you have to run through the preceding rows to see whether the current value has occurred before.
If you stipulate order on the field of interest, you should be able to check the value in the row event and increment a counter when the value changes.
|
|
|
|
Re: Running Count Distinct [message #557663 is a reply to message #557563] |
Wed, 08 September 2010 13:08 |
|
Yes, the onFetch event would be the place. You need two tracking variables: varValue and runCount. I suspect you have to define and initialize those in the beforeOpen event, but someone more familiar with dataset event scripting would have better information. It's not something I've had to do for my purposes.
|
|
|
|
|
|
Re: Running Count Distinct [message #824414 is a reply to message #824063] |
Mon, 19 March 2012 16:33 |
|
Thanks for posting. Just an FYI, BIRT does have an aggregation
extension point. This sounds like an excellent option for this.
Take a look at this post:
http://birtworld.blogspot.com/2010/10/birt-duplicate-rows.html
Jason
On 3/19/2012 4:00 AM, Tobias Feldker wrote:
> Great I just found my own post again :d I will post my solution since
> Karthik asked for it.
>
> A running count distinct can be acquired using the script methods on the
> DataSet.
>
> For my solution, it is necessary that the DataSet is sorted by the
> column that should be counted distinct running. The sort order would
> determine whether the smallest or the biggest entry gets the count 1.
>
> First create a computed column that gets the default 1. In my expample
> the column is called "computedCoulmun".
>
> Second you have to initialize the variables you want to use in the
> onFetch()-script. I use java.lang.Integer just for initialization
> issues, I didn't find another way to securely initialize my variables.
> befroreOpen() would look like this:
>
> importClass( Packages.java.lang.Integer );
> oldCol = new Integer(0);
> oldCount = new Integer(0);
> count = new Integer(0);
>
> Third step would be that little onFetch()-Script. You would have to
> replace "columnToBeCountedDistinct" with the name of the column that
> should get a running count distinct. onFetch()-Script:
>
> col = row.columnToBeCountedDistinct;
> count = row.computedCoulmun;
> if (oldCol != col) {
> oldCol = col;
> oldCount = BirtMath.add(oldCount, 1);
> }
> row.columnToBeCountedDistinct = oldCount;
>
>
> I hope this post helps all people that want to create a manual count
> distinct.
>
> I would appreciate a BIRT aggregation that would do the count for me and
> that works without sorting the DataSet first.
|
|
|
Powered by
FUDForum. Page generated in 0.04584 seconds