• RSS

Statistics

  • Entries (3)
  • Comments (0)

Categories

Aggregate elements in Inka 

Friday, March 21, 2008 9:32:48 AM

I've just added aggregate support to Inka. Still a few bugs, but should work fine in most cases.

Definitely worth a new release, and also worth this blog post. This is the first post on this site, so I should probably start with some introduction, but that will wait, and also you can read it all in the supplied docs. So, I jump straight to the aggregate element and how to use it.

So, we've got aggregate functions, like Count(), Sum(), etc. In Inka, they are implemented as classes that implement IAggregateFunction. The interface consists of a Sub (a method that returns void), Current(), that executes an operation on the object's internal state for each item in the data source, and the Value property that just returns the result. So, for example, if we take the Count class, the Current method increments the internal counter by one, and the Value property returns the value of this counter.

These aggregates appear in the Text property of the AggregateElement instance. They should be enclosed in curly brackets, like this: {Count()}. The brackets that appear after the name of the function can contain arbitrary number of arguments. As usual, data fields should appear in square brackets, so you have stuff like this: {Sum([Value])}. In addition, the AggregateElement inherits from the DataElement class, so you can use square brackets whenever you want to use a field of the current DataItem. Combined together, you can use text like "Category [CategoryName] contains {Count()} records."

There are three special properties of the AggregateElement class related to the data it uses. The DataSource property lets you to set the data source manually. However, you probably don't want to use it, unless you do everything manually. The way you are suppose to do that, is to use the SourceSection property. This property points to the section you are aggregating. Another useful property is ContainerSection. In order for everything to work correctly, your element and the source section should have a common container section. If this is the immediate container of your element, you don't have to set this property; however, if you put your element a level or two deeper, you need to indicate the common container.

So, suppose you have:

  1. MainSection that is part of your report;
  2. CategorySection inside the MainSection;
  3. DetailSection inside the CategorySection;
  4. the DataItem property value of the DetailSection has a Value property;
  5. GroupFooter section inside the MainSection;
  6. your aggregate element inside the GroupFooter.

In order to summarize the data contained in the DetailSection exemplars, you should set the SourceProperty of your aggregate element to DetailSection. For example, you can show the sum of all values using the Text property set to "The sum of values is {Sum([Value])}". Or you can display the number of records using the Count function. On the other hand, you might want to display the number of category groups. In that case, set the SourceSection property to CategorySection.

In both cases, since the aggregate element is not a child of MainSection, you should set the ContainerSection property to MainSection.

Copyright 2008 Sm-Art
8 + 6 =  

Site Map | Printable View | © 2008 - 2010 Your Company Name

Powered by mojoPortal | HTML 5 | CSS | Design by styleshout