The problem
Then I got an interesting ask: "In Apex Interactive report, calculate index column as average on two other visible columns and show "Total average". First part was easy-SQL column as average calculation of other two. But problem came when I wanted to show "Total average" value, because I couldn't use implemented IR feature "Aggregation" on average column-average computation on average values is not correct average!!! So I let this value to blank to see what can be done later.Let me show a picture of problem with report with activated "Control Brake" on first two columns, what results as virtual two reports:
The solution
Analyzing page source with Web Developer show me next data: Hopefully there was created placement for average calculation, but it was blank.Thanks to Davor Zelić who has enough nerves and will to handle this problem, solution was made in a classic way-custom java script.
The result is this source javascript file which setAggrIndexValue method is the one that do the work, while getElementsByAttribute method is used to find proper values for calculation.
This java script file, as usual, has to be uploaded in workspace/application image repository (or place on Apache images location if using Apache as WEB server), and put it's call directly on custom page header or in page template (find more appropriate solution).
After that on page, where Interactive report is placed, fill call of java script function in page property in "Footer" part of "Header and Footer" section as: If you start that report and look now in WEB Developer debuger inspector, you'll see that values are filled properly-with real average values. Result is exactly what I wanted, even thought if there are more then one average calculation on page ("Control Brake" case).
The End
As you see, this solution is pretty generic and real text function call can be viewed as pure text in mentioned java script source, last three lines as comment. The only condition is that calculation values are visible in Interactive report, what is more then common requirement and reasonable condition.Beside all thisi approach allow very easy implementation of other custom aggregation when you have need for that.
Hope this helps someone.
Cheers!
Nice trick
ReplyDeleteWhy not use an Oracle Analytical functions to handle doing the average? Using a rollup on your columns with the proper grouping would provide the weighted average you want, right??
ReplyDeleteThe result is not the problem but how to show it in Apex page in footer with correct numbers.
DeleteHi,
ReplyDeletenow i am facing the problem with to display that row as first row.
i need to display the total aggregate result as first row of the report
can you please help me on this?
regards
shekar
For that you can use analytic functions directly in oracle.
DeleteThanks Damir,
ReplyDeleteI need to display only grand totals not sub totals, for my requirement i should use APEX aggregation functionality.
is there any way to display as header or first row?
regards
shekar
Look in mine js code.
DeleteWith WEB developer (in FF) find heading name element and change it according that value you'll find in header. Script is pretty simple for debugging.
Rg
Damir
Hi Damir,
ReplyDeleteThanks for your reply, really i am not that much intelligent.
could you please explain how to write and where i should write that one?
best regards
sheakr
Send me an Excel with exact data (number of columns and proper names) what you need and will try when I get time.
DeleteOr even better make an demo of your app on Oracle public Apex site, send me login data.
"http://apex.oracle.com" is wher you can show your demo
DeleteHi,
ReplyDeleteHere i am showing my app demo.
http://apex.oracle.com/pls/apex/f?p=22641:2
Username and Password : test
I just need to display that colored row as first row of report..
regards
Shekar
OK.
DeleteIf you display first row as normal row then total at the end will not work. If this is OK, then let me know I'll try to make your wish alive-seems to me possible
give me login data for workspace t be able to test code
DeleteThanks Damir,
ReplyDeleteWorkspace : chandu_jnet
Hi Damir,
ReplyDeleteThanks for this great information. I have implemented the solution successfully, but when viewing it in IE9 - the calculated value doesn't appear. I have tested it in Chrome/Firefox and on my iPad(Safari).
Can you please advise?
Regards
Mynhardt
Hi Damir,
ReplyDeleteI am trying to customize the IR report aggregates using your your approach, but the thing is i am using oracle apex 19.1 & in my case i want to calculate the overall percentage and this overall percentage should change automatically even when I apply control on columns. Please if you can assist that will be really helpful. Here is the post that i posted on apex community https://community.oracle.com/message/15425896#15425896
Thanks,
Ragu