Auto sum Column accumulated value in gridview
The principle seems simple but I'm in trouble. Did anyone have an example or script to auto sum of a column in the gridview. Explain, I have a gridview with the columns:
amount, unitary value, total value and accumulated value. I need the accumulated value column add the previous value
to the current value. For example:
quantity unitary_value total_value accumulated_value
10 10,00 100,00 100,00
20 50,00 1.000,00 1.100,00
5 500,00 2.500,00 3.600,00
Basically it would be up. The column value (accumulated value) takes the value of the previous line and adds to the current value.
If you can help !!
Thank you for your attention.
Thank you for your attention.
No you're right with the calculation of the first post, I got it wrong. Now check the below solution, you need to use RowDataBound event of the gridview to do the calculation and print in the cell:
//This is just a method to fill the datatable with dummy data(you can ignore in your code)static DataTable GetTable()
// Here we create a DataTable with four columns.
DataTable table = new DataTable();
table.Columns.Add("quantity", typeof(double));
table.Columns.Add("unitary_value", typeof(double));
table.Columns.Add("total_value", typeof(double));
table.Columns.Add("accumulated_value", typeof(double));
// Here we add five DataRows.
table.Rows.Add(10, 10, 0, 0);
table.Rows.Add(20, 50, 0, 0);
table.Rows.Add(30, 40, 0, 0);
return table;
protected void Page_Load(object sender, EventArgs e)
//Bind the gridview to the datatable
GridView1.DataSource = GetTable();
GridView1.DataBind();
//Global var to keep accumulated value of each rowo
double _accumulatedvalue = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
//Create total value column by multiplying cells 1 and 2(maybe you don't need this)
Double val = Convert.ToDouble(e.Row.Cells[0].Text) * Convert.ToDouble(e.Row.Cells[1].Text);
e.Row.Cells[2].Text = val.ToString();
//Accumualated value and fill the cell related (you can replace val below with Convert.ToDouble(e.Row.Cells[2].Text)
_accumulatedvalue = _accumulatedvalue + val;
e.Row.Cells[3].Text = _accumulatedvalue.ToString();
Fouad Roumieh
Similar Messages
-
How can I sum the values in a given column on sheet 1 i.e. A1:A50 based on the adjacent columns specific value i.e. B1:B50 = “Dinning Room” on sheet 2
For Example:
SHEET 1
A
B
$50
Dinning Room
$800
Dinning Room
$300
Kitchen
$1,000
Master Bedroom
$100
Dinning Room
SHEET 2
Display the total SUM amount of each Project based on Sheet 1
Project Name
Total Cost
Dinning Room
$950
Kitchen
$300Would be a good idea to open iWork Formulas and Functions User Guide and search for the description of the function named SUMIF
The Guide is available for every user thru the Help menu.
Yvan KOENIG (VALLAURIS, France) jeudi 19 mai 2011 17:32:42
Please :
Search for questions similar to your own before submitting them to the community
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer ! -
Regarding alv function of summing up the values of columns.
hi friends:
could you please tell me how to sum up the values of columns.
for example, there are columns of room rent, expense of cell phone call,
expense of taxi fee.
thank you very muchhi For calculating one more coloum . try this logic
write this piece of code in wddoinit
data : lt_column type salv_wd_t_column_ref,
ls_column type salv_wd_s_column_ref,
lo_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule.
* display columns in correct order
lr_column_settings ?= wd_this->lr_config.
lt_column = lr_column_settings->get_columns( ).
loop at lt_column into ls_column.
case ls_column-id.
when 'ROOM_RENT'.
* aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = 'ROOM_RENT'
receiving
value = lr_room_rent_total.
* create aggregate rule as total
call method lr_field_amnt->if_salv_wd_aggr~create_aggr_rule
exporting
aggregation_type = if_salv_wd_c_aggregation=>aggrtype_total
receiving
value = lv_aggr_rule.
when 'CALL'.
* aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = 'CALL'
receiving
value = lr_call_AVG.
* create aggregate rule as total
call method lr_field_amnt->if_salv_wd_aggr~create_aggr_rule
exporting
aggregation_type = if_salv_wd_c_aggregation=>AGGRTYPE_AVERAGE
receiving
value = lv_aggr_rule.
endcase.
endloop.
Regards
Chinnaiya -
Javascript errors - Summing columns using Javascript
Hi
I have two regions on a page which are tabular forms that I have manually setup using APEX_ITEMS that I would like to use some JavaScript to pick up the values entered and sum that row up. I used Vikas example for tabular form calculation and it works perfectly for 1 region however if I have two regions it seems to give me the following error message in Firefox:
g_table.rows[rownum].cells[getCellPos(g_table, html_GetElement("COL05"), "column")] has no properties
Which I gather is because there are two columns on the page named COL05 and idea how I could get around this problem.
I've put an example here: http://apex.oracle.com/pls/otn/f?p=35414:4Hello,
It could be a bit difficult to auto sums a row, as
usually rows include non-numeric columns. In any
case you can always use a computation column in your
select statement, or build a derived column in the
report attributes tab. The problem is to update these
columns in real-time, after a specific cell has been
changed, and for that you need JavaScript.I realised this thats why I wanted to pickup the column and Row and then I would be able to replace the value in the specified column ie. total column using javascript for each row.
I’m not sure I’m following you, but if you mean the
current (active) rownum per displayed report page,
you can use the #FIRST_ROW_FETCHED# and
#LAST_ROW_FETCHED# substitution strings, in the
footer of the report region.
If you meant something else, please elaborate a bit
more.Look at the revised demo app http://apex.oracle.com/pls/otn/f?p=35414:4 as you can see in this particular example each region returned 15 rows of data. I wondered if there was a way to pick up the last row returned so that I could use the same javascript function I use to calculate the rows I could update that specific column/total row. Example, in my demo app you will see a null row returned I would like to find this row then update the values. -
Calculation of accumulated values
Hi experts!
I'm looking for a solution on how to accumulate a value, say 0AMOUNT, over time. The reason is a requirement to look att accumulated values although only posted amounts per fiscal perioid is available from the BC extractor. So the posted amounts need to be summed up over the time dimension in order to calculate a (also historical) balance for each fiscal period. How would you best implement such a solution?
I have considered:
1) define a hierarchy on 0fiscper that groups together fiscal periods into an aggregated level - e.g 2001-01 in the hierarchy would contain actual fiscper 2001-001, 2001-02 in the hierarchy would contain both 2001-001 and 2001-002 (thereby causing an accumulated value when summed up), and so on ...
2) Do the accumulation in an update routine by some ABAP code - im not quite sure on how to do this - any suggestions would be helpul!
3) Dynamically calculate the sum of 0amount in the report although this would be the least efficient soulution...
Any help/suggestions is appreciated!
Many thanks,
DavidJust as you say i'm also sure that it "can" be done, i'm just looking for the best solution. And possibly some hints in implementing that one.
It is true that I have 0AMOUNT per fiscal year/period, but the option to simply sum up 0AMOUNT in the report is not feasible since that would require to much computation to be done online (we keep history for a long time back). Hence I would need to precompute the accumulated value per fiscal period and save it in the cube as a non-cumulative balance. So when the user restricts on, say fiscper "2003-01" in the query, the accumulated balance for 2003-01 is directly retrieved from the cube.
Many thanks,
David -
To calcuate the accumulated value
Hello,
I would like to write a calc script for the following scenario: I have a series of data value, and would like to calcuate the accumulated value based on the sequence of from the smallest to the largest. The case is like this:
The input is as following
Case 1
Acct1: 10
Acct2: 5
Acct3: 8
Acct4: 15
I would like to calcuate the accumlated value based on the data value, the caulcated result is at column Case 2:
Case 1 Case 2 Rank
Acct1: 10 23 3
Acct2: 5 5 1
Acct3: 8 13 2
Acct4: 15 38 4
I can easily use the rank function to rank the data value of "Case1", but after that how can I use this rank to cauculate the accumluated values? The data value may change, (from time to time, for example).
Any good suggestions? Thanks in advanceHi There
Try this script below. I have done this in the SAMPLE app. script may look crazy, but I have tested this and it works. Also what makes it a little more complicated is the fact that ranking can give you duplicate rank values, so I have designed this to get around that problem.
Thanks
Anthony
SET UPDATECALC OFF;
VAR AccountCount=0;
VAR CurrRank=0
/*Create blocks in case dimension as mine is sparse*/
FIX(Local,FY13,BegBalance,Forecast,Working,"E01_101_1110",@RELATIVE("TotaltestAccount",0),"HSP_InputValue")
DATACOPY "Case1" TO "Rank";
DATACOPY "Case1" TO "Case2";
DATACOPY "Case1" TO "Sequence";
DATACOPY "Case1" TO "Case1Seq";
ENDFIX
FIX(Local,FY13,BegBalance,Forecast,Working,"E01_101_1110",@RELATIVE("TotaltestAccount",0),"HSP_InputValue")
"Case2" = #missing;
"Sequence"= #missing;
/*Create a sequence for the list of accounts so that if you for any chance have a value that is the same the rank will give a unique rank value - because this becomes a problem later*/
"Sequence"= (@SHIFT("Sequence",-1,"Acc1":"Acc5") + 0.00000000001);
/*Rank case1 and add the sequence to give you the unique ranking and then * -1 to reverse the rank*/
"Case1Seq" = "Sequence" + @RANK(SKIPNONE,"Case1",@RANGE("Case1",@RELATIVE("TotaltestAccount",0))) * -1;
ENDFIX
FIX(Local,FY13,Forecast,Working,"E01_101_1110",@RELATIVE("TotaltestAccount",0),"HSP_InputValue")
/*Next rank the previous rank from above to now populate the unique ranking of case 1 in dec order*/
"Rank"(
IF(@ISMBR("BegBalance"))
"Rank" = @RANK(SKIPNONE,"Case1Seq",@RANGE("Case1seq",@RELATIVE("TotaltestAccount",0)));
ENDIF
/*Populate the max ranking value to start the variable counter*/
AccountCount = @MAXSRANGE(SKIPMISSING,"Rank"->"BegBalance",@RELATIVE("TotalTestAccount",0));
CurrRank = AccountCount;
ENDFIX
FIX(Local,FY13,"Case2",Forecast,Working,"E01_101_1110",@RELATIVE("TotaltestAccount",0),"HSP_InputValue")
/*Calculate the lowest case 1 value first or highest rank value, then make curr rank equal to highest rank -1 */
"BegBalance"(
IF(AccountCount == "Rank")
"Begbalance" = "BegBalance"->"Case1" ;
CurrRank = CurrRank - 1;
ENDIF
/*Then loop through the process reducing the current rank variable by 1 each time*/
LOOP(100)
"BegBalance"(
IF(CurrRank == "Rank")/* i.e rank ==4 */
"Begbalance" = @MAXSRANGE(SKIPMISSING,"Case2"->"BegBalance",@RELATIVE("TotalTestAccount",0)) +"BegBalance"->"Case1";
CurrRank = CurrRank - 1;/*then make rank == 3*/
ENDIF)
ENDLOOP;
ENDFIX -
Insert data into Access with Auto-Increment column
Is there anyone out there that has come across this problem I am experiencing?
I have a form I'm trying to submit to an Access DB that has an Auto-Incremented Table Column. I have followed Stefan Cameron's instructions to a "T" on his blog page here:
http://forms.stefcameron.com/2006/09/18/connecting-a-form-to-a-database/
but I keep getting the following error"
GeneralError: Operation failed.
XFAObject.open:10:XFA:form1[0]:mysubform[0]:myEIFform[0]:overflowLeader[0]:Submit[0]:click
open operation failed. [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
My OLEDB Connection Record Source is the SQL Query which reads: SELECT FedTaxID, LegalID FROM dbtest; My simple test DB is Access and its only 3 columns; dbID, FedTaxID, LegalID. dbID is the Auto-Incremented Column.
If I remove the Auto column from my DB table it inserts just fine but I get this error:
GeneralError: Operation failed.
XFAObject.open:10:XFA:form1[0]:mysubform[0]:myEIFform[0]:overflowLeader[0]:Submit[0]:click
ado2xfa operation failed. Item cannot be found in the collection corresponding to the requested name or ordinal.
I've looked over alot of the blogs and other help forums and there's info on Selects, I don't find much on Inserts.
Can anyone direct me in the right direction? Thank you.First, please pay attention to the forum in which you are posting. This particular post would be more appropriate to tsql rather than datamining. Second, what specific problem are you trying to solve. The code you posted appears to be
correct. I will say that your DataTable will likely be a source of future problems if it contains only the 2 columns. -
I have a very simple table used for debugging:
CREATE TABLE APPS.XX_DEBUG_TMP
TEMP_VALUE VARCHAR2(255 BYTE),
TEMP_DATE DATE
)Then I can use it to store values as my pl/sql is processed - e.g.:
INSERT INTO XX_DEBUG_TMP (TEMP_VALUE,TEMP_DATE) VALUES ('line 740 l_username value check:' || l_username,SYSDATE); COMMIT;Trouble is that if a load of debug statements get processed with the same timestamp, I can't see which came first.
Can I modify my table creation SQL to include an ID column which just increments for each row that is added to the table?
I'm familiar with how to do it in MySQL (sorry - I know this is an Oracle forum - but am just putting this here to show what I mean):
CREATE TABLE `XX_DEBUG_TMP` (
`TEMP_ID` MEDIUMINT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`TEMP_VALUE` VARCHAR( 255 ) NOT NULL ,
`TEMP_DATE` DATETIME NOT NULL
) ENGINE = MYISAM ;Is it that simple with Oracle? Probably not!
Any advice much appreciated.
ThanksThere is no auto increment column in Oracle. However, you can create a sequence.
CREATE TABLE APPS.XX_DEBUG_TMP
TEMP_ID NUMBER NOT NULL PRIMARY KEY,
TEMP_VALUE VARCHAR2(255 BYTE),
TEMP_DATE DATE
CREATE SEQUENCE APPS.XX_DEBUG_TMP_SEQ;Then in your insert statement do this:
INSERT INTO XX_DEBUG_TMP (TEMP_ID,TEMP_VALUE,TEMP_DATE) VALUES (APPS.XX_DEBUG_TMP_SEQ.NEXTVAL,'line 740 l_username value check:' || l_username,SYSDATE); Another possible solution to your problem would be to use a TIMESTAMP data type instead of a DATE data type. It has fractional second resolution (up to 9 places I believe). -
Problem getting accumulative value by a user defined week
I have a requirement where I have to accumulative values by week where a week is defined as Sunday to Saturday. For example:
date value acc_value
9/1/2010 2 2 Wed
9/2/2010 5 7 Thur
9/3/2010 3 10 Fri
9/4/2010 4 14 Sat
9/5/2010 8 8 Sun value is reset
9/6/2010 2 10 Mon
9/7/2010 1 11 Tue
9/8/2010 4 15 Wed
9/9/2010 7 22 Thu
9/10/2010 4 26 Fri
9/11/2010 5 31 Sat Any help would be appreciated.
Thanks.Try this:
with my_table as (select to_date('01/09/2010', 'dd/mm/yyyy') dt, 2 value from dual union all
select to_date('02/09/2010', 'dd/mm/yyyy') dt, 5 value from dual union all
select to_date('03/09/2010', 'dd/mm/yyyy') dt, 3 value from dual union all
select to_date('04/09/2010', 'dd/mm/yyyy') dt, 4 value from dual union all
select to_date('05/09/2010', 'dd/mm/yyyy') dt, 8 value from dual union all
select to_date('06/09/2010', 'dd/mm/yyyy') dt, 2 value from dual union all
select to_date('07/09/2010', 'dd/mm/yyyy') dt, 1 value from dual union all
select to_date('08/09/2010', 'dd/mm/yyyy') dt, 4 value from dual union all
select to_date('09/09/2010', 'dd/mm/yyyy') dt, 7 value from dual union all
select to_date('10/09/2010', 'dd/mm/yyyy') dt, 4 value from dual union all
select to_date('11/09/2010', 'dd/mm/yyyy') dt, 5 value from dual)
-- end of mimicking your data in a table called my_table
select dt,
value,
sum(value) over (partition by trunc(dt+1, 'iw') order by dt) acc_value,
to_char(dt, 'dy') dy
from my_table
order by dt;
DT VALUE ACC_VALUE DY
01/09/2010 2 2 wed
02/09/2010 5 7 thu
03/09/2010 3 10 fri
04/09/2010 4 14 sat
05/09/2010 8 8 sun
06/09/2010 2 10 mon
07/09/2010 1 11 tue
08/09/2010 4 15 wed
09/09/2010 7 22 thu
10/09/2010 4 26 fri
11/09/2010 5 31 sat -
Can we specify prefix for an auto increment column
Hi all,
I want to create an auto increment column in oracle using oracle sequences.
But i want to specify a prefix for the value appearing after increment.
Prefix will remain constant.
If we can how can i do that.
And one more thing is i will call the sequence using a trigger only for a specified condition.My doubt here is can i allow nulls for auto incrementing column
With Regards<s></s>
-- Samples.
create table tab1
(id varchar2(6) constraint p_tab1 primary key
,data varchar2(255)
create sequence seq_tab1;
create or replace
trigger trg_tab1
before insert on tab1
for each row
declare
p_prefix varchar2(2) := 'AA';
begin
if (:new.id is null) then
select p_prefix||to_char(seq_tab1.nextval,'fm0009') into :new.id from dual;
end if;
end
-- Test
SQL> insert into tab1(data) values('abc');
1 row created.
SQL> insert into tab1(id,data) values('BB9999','xyz');
1 row created.
SQL> select * from tab1;
ID
DATA
AA0001
abc
BB9999
xyz -
Hi All,
I have a DG with multiple columns (Numbers), the values are coming from an array collection.
What is the best way to sum couple columns? like
Column01 + Column02 = ColumnTotal
I try using a labelFuction in the column like:
private function sumColumns(item:Object, col:DataGridColumn):String {
var tempNumber:Number = parseFloat(item.column01) + parseFloat(item.column02);
return tempNumber.toString();
But the result doesn't reflect in the arraycollection. Should I create the column with values at the time of received the results?
If I do this, when I change the value in any of the columns 01 or 02 it doesn't change the total.
Thanks for your help.
JohnnyYes, immediately after u receive the result create another property in the and assign the sum of two columns to it and then assign it to the datagrids data provider. the property that you create will be mapped to the column which shows the sum. if you are using label function to get the sum you can se a lot of calls med to the label function even when you scroll, this is all unnecessary memory hog.
-
Add auto increment column to trigger
I want to add auto increment column to after insert trigger. so how can I do that?
this is my query.
Create Sequence Up_Seq
Start With 1
Increment By 1
nomaxvalue;
Create Or Replace Trigger Upf_Trig
After Insert On members
Referencing New As New
For Each Row
Begin
Insert Into Upf_Kgl(Member_Id,Mem_Name,Nic,Division)
Values (Up_Seq.Nextval
*,:New.Mem_Name*
*,:New.Nic*
*,:New.Division);*
end upf_trig;
It's worked. but when inserting values to members table, there is an error.
this is the error
Error starting at line 21 in command:
Insert Into Members(Mem_Name,Nic,Full_Name,Age,Sex,Mar_State,Birth_Date,Division,Religon)
Values(
*'IA Nawagamuwa'*
*,'883324356V'*
*,'Isuru Aravinda Nawagamuwa'*
*,'22'*
*,'Male'*
*,'Single'*
*,'21-Dec-88'*
*,'kgl'*
*,'Buddhist')*
Error report:
SQL Error: ORA-00001: unique constraint (SYSTEM.SYS_C004077) violated
ORA-06512: at "SYSTEM.UPF_TRIG", line 2
ORA-04088: error during execution of trigger 'SYSTEM.UPF_TRIG'
*00001. 00000 - "unique constraint (%s.%s) violated"*
**Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.*
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
**Action: Either remove the unique restriction or do not insert the key.* -
Hi,
I am developing a report which consists of percentage which is auto summing up in the webi report, so i want to avoid the auto sum for this column and make it to show the percentage for all the group of records.
Can any one help on this issue.>
wavery wrote:
> Hello,
>
> Can you provide more details as to what you are doing? How is your report set up?
>
> Thanks
Hi wavery,
I could able to avoid the autosum, but still i stuck at point where i cannot reproduce the report to fulfill my requirment.
Below is a test case for it :
Input Data :
Treaty_Number Book_date Amount Percentage
1 2010-07-12 1000 80
1 2010-07-11 1400 100
1 2010-07-10 2600 90
2 2010-07-11 1000 70
2 2010-07-09 1000 100
2 2010-07-08 2000 50
Current Output :
Treaty_Number Amount Percentage
1 5000 100
2 4000 100
Expected Result :
Treaty_Number Amount Percentage (Max Book_dateu2019s)
1 5000 80
2 4000 70
Here i need to display the percentages of max of booking_date -
From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?
Hi,
Use NVL or COALESCE:
NVL (col_a, col_b)
Returns col_a if col_a is not NULL; otherwise, it returns col_b.
Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Under the column firld value new variable needs to be displayed in
hi
i ahve a query
presently in sap script output in main window
these three fields are coming i want to add a new line ie bar code for the field value which is coming below it
example
present output
number item total amount unitvalue
001 dxs 22222 3456
002 tcg 44545 45464
desired output change needed
number item total amount unitvalue
001 dxs 22222 3456
bar code for 3456
002 tcg 44545 45464
my question is kindly let me know how to increase the space next line how to get below the earlier value coming
what is code for next line and if i put it below that field in the column unit value will it be displayed and automatically space created for whole line??? and output as above comes
pls suggest
regards
Aroraclosed
duplicate thread
Maybe you are looking for
-
Can i have multiple iTunes accounts on the time Capsule
We are think about buying a time capsule for the family, we all have are own accounts. I want to make sure that they will work to back up to the time capsle with out anyproblems or anything being mixed up.
-
what is the arrtibute value of this hex1 type .. in CL_ABAP_CHAR_UTILITIES. hex1 TYPE x VALUE '0D', my req is this value is in structure n data: begin of itab_input c1(40) type c value 'hgfsdhfjsdf'. hex1 type x value '0D', end
-
How to use a List interface?
Hi, anybody can help me about using List interface? I need one example please. Thanks in advance and excuse me for my english. Daniele.
-
JPanel repaint in an ActionListener and Frame title change
I have been trying to repaint a JPanel from a method in a nested class. The JOption pane works that retrieves the string for the color and I believe the string is being converted to a color properly, however when the repaint takes place nothing happe
-
Buenas noches, tengo un gran problema, cuando inicio mi mac book air, aparece la pantalla para iniciar desde macintosh HD o Recovery Hd, le doy a macintosh, aparece mi nombre de usuario pero cuando escribo la contraseña es como si estuviera presionan