Friday, February 1, 2013

Oracle Analytic Functions for Total and Average Calculation in ADF BC

What is great about ADF BC - this framework is very close to the DB and makes data management and analysis operations implementation really easy. There are different ways to implement total and average value calculation. The best way probably is to use Oracle DB Analytic Functions. Using analytic functions minimizes custom Java code, simplifies handling search from Query criteria of from table filter. There is no need to specify GROUP BY in SQL when using analytic functions, this makes easier ADF BC VO implementation.

You are welcome to download sample ADF 11g R2 application - Two calculated attributes are added to the Employees VO, both of them are initialized from SQL statement calling analytic function. Here is example for total calculation - check SQL statement for calculated attribute:

Here is for the average:

This is how resulting SQL statement looks for ADF VO with two calculated attributes based on analytic function:

This is all about ADF BC. On ADF UI you need to define in page definition two attributes for calculated fields:

Reference these attributes from table column footer for example:

It works smooth on runtime - search is executed from ADF query, total and average reflect salary data:

If you want, type search criteria into table filter and execute additional filtering - total and average values will be automatically recalculated based on filtered table data:


Deepak Siddappa said...

Nice Article.

Unknown said...

Thank you for good Articles
I do like the instruction in blog but when I do not search anything and I want to show all records return null for sum.
how can I have sum of amount column without any criteria???

Andrejus Baranovskis said...

I tested - if there is not criteria and if all records are returned - total sum is correctly displayed.


Patrik Frankovic said...

Hi Andrejus,
I've put some analytic function in my view object but directly in sql text in expert mode and totals don't work after filtering or allways shows same result(Apsolute total). I guess that in this case created attributes are not of calculated item type and adf does not refresh them.
So, solution is to create them view regular add new attribute and put analytic function in their default value SQL expression as you mentioned.