Sum rows of Column A based on distinct values of Column B
Hello everyone,
below is my xml
<ROWSET>
<ROW>
<ORDER_NO>103-4385509</ORDER_NO>
<SITE_NO>103</SITE_NO>
<ORDER_ID>4385509</ORDER_ID>
<CUSTOMER_ID>2676832</CUSTOMER_ID>
<TAX_AMOUNT>.33</TAX_AMOUNT>
<CREATED_DATE>08/20/2010</CREATED_DATE>
<USER_CREATED>TSDAL671</USER_CREATED>
<Delivery_Method>CARRY OUT STORE</Delivery_Method>
<Entered_By>TSDAL671</Entered_By>
<SKU_NO>321182</SKU_NO>
<NAME_TEXT>MGR_OVERRIDE</NAME_TEXT>
<ATTRIBUTE_ID>319</ATTRIBUTE_ID>
<ATTRIBUTE_VALUE>Override Done</ATTRIBUTE_VALUE>
<DETAIL_SEQ_NO>1</DETAIL_SEQ_NO>
</ROW>
<ROW>
<ORDER_NO>103-4385509</ORDER_NO>
<SITE_NO>103</SITE_NO>
<ORDER_ID>4385509</ORDER_ID>
<CUSTOMER_ID>2676832</CUSTOMER_ID>
<TAX_AMOUNT>.33</TAX_AMOUNT>
<CREATED_DATE>08/20/2010</CREATED_DATE>
<USER_CREATED>TSDAL671</USER_CREATED>
<Delivery_Method>CARRY OUT STORE</Delivery_Method>
<Entered_By>TSDAL671</Entered_By>
<SKU_NO>321182</SKU_NO>
<NAME_TEXT>OEDTL_TAX_INFO</NAME_TEXT>
<ATTRIBUTE_ID>314</ATTRIBUTE_ID>
<ATTRIBUTE_VALUE>441130760|441130760|441130760|1|1|1|20100820|2676832|2|SPARTS|</ATTRIBUTE_VALUE>
<DETAIL_SEQ_NO>1</DETAIL_SEQ_NO>
</ROW>
<ROW>
<ORDER_NO>103-4385509</ORDER_NO>
<SITE_NO>103</SITE_NO>
<ORDER_ID>4385509</ORDER_ID>
<CUSTOMER_ID>2676832</CUSTOMER_ID>
<TAX_AMOUNT>.18</TAX_AMOUNT>
<CREATED_DATE>08/20/2010</CREATED_DATE>
<USER_CREATED>TSDAL671</USER_CREATED>
<Delivery_Method>CARRY OUT STORE</Delivery_Method>
<Entered_By>TSDAL671</Entered_By>
<SKU_NO>412679</SKU_NO>
<NAME_TEXT>OEDTL_TAX_INFO</NAME_TEXT>
<ATTRIBUTE_ID>314</ATTRIBUTE_ID>
<ATTRIBUTE_VALUE>441130760|441130760|441130760|1|1|1|20100820|2676832|2|0035|</ATTRIBUTE_VALUE>
<DETAIL_SEQ_NO>2</DETAIL_SEQ_NO>
</ROW>
i have to display 3 rows but while doing sum of TAX_AMOUNT grouped by ORDER_ID, i need to sum only for 2 records based on the distinct value of DETAIL_SEQ
so my output should be some thing like below
ORDER_ID|TAX_AMOUNT|DETAIL_SEQ|ATTRIBUTE_ID
4385509|0.33|1|319
4385509|0.33|1|314
4385509|0.18|2|314
SUM = 0.51
Note : i cannot do distinct in the sql becuase attribute_id is different for same DETAIL_SEQ_NO.
I tired doing <?sum([xdoxslt:distinct_values(current-group()/DETAIL_SEQ_NO)]/TAX_AMOUNT)?>
it didn't work.
Can anyone please help me!!
Thanks in Advance!!
That syntax wont work.
One method of doing.
<?for-each-group:/ROWSET/ROW;ORDER_NO?>
<?for-each:current-group()?>
<?ORDER_NO?> <?TAX_AMOUNT?> <?DETAIL_SEQ?> <?ATTRIBUTE_ID?>
<?end for-each?> <?xdoxslt:set_variable($_XDOCTX,'sum_attr',0)?>
<?for-each-group:current-group();DETAIL_SEQ_NO?>
<?xdoxslt:set_variable($_XDOCTX,'sum_attr', xdoxslt:get_variable($_XDOCTX,'sum_attr')+ TAX_AMOUNT)?>
<?end for-each?><?xdoxslt:get_variable($_XDOCTX,'sum_attr')?>
<?end for-each?>
Similar Messages
-
Insert a number of rows for tabular form based on frequency value
Hi,
I have a page with two search items.
Based on the values in the search item, a report is created as tabular form.
The information displayed has a frequency column.
Values for frequency can be Q, Y, M, D
I would like to know if it is possible to to load the form with a standard numbers of row depending on the frequency.
Example: If frequency is Q ,then when i click the go button in the search region, the tabular shoud load with the information displaying 4 rows, even if the information returned is less than 4 rows.
If frequency is Y ,then when i click the go button in the search region, the tabular shoud load with the information displaying 2 rows, even if the information returned is less than 2 rows.
When no data is found, the form should load displaying a number of empty rows depending on the frequency.
ThanksFollowing this example:
http://apex.oracle.com/pls/otn/f?p=31517:209
you should be able to achive that.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
How to merge values in a row, based on distinct values in another column
I have a table like
updatedby updateddate text
John 01-May-2009 Approval record 1 added
John 01-May-2009 Approval record 2 added
David 02-May-2009 Approval record 1 removed
I need the values of text column to be concatenated and displayed for unique records of (updatedby updateddate). The output is something like
updatedby updateddate text
John 01-May-2009 Approval record 1 added, Approval record 2 added
David 02-May-2009 Approval record 1 removed
I had planned to do it using PLSQL. Is there a way to get this done by SQl?.. Kindly suggestPrior to 10g:
with t as (
select 'John' updatedby,to_date('01-May-2009','dd-mon-yyyy') updateddate,'Approval record 1 added' text from dual union all
select 'John',to_date('01-May-2009','dd-mon-yyyy'),'Approval record 2 added' from dual union all
select 'David',to_date('02-May-2009','dd-mon-yyyy'),'Approval record 1 removed' from dual
select updatedby,
updateddate,
ltrim(sys_connect_by_path(text,','),',') text
from (
select t.*,
row_number() over(partition by updatedby,updateddate order by text) rn,
count(*) over(partition by updatedby,updateddate) cnt
from t
where rn = cnt
start with rn = 1
connect by updatedby = prior updatedby
and updateddate = prior updateddate
and rn = prior rn + 1
order by updateddate,
updatedby
UPDAT UPDATEDDA TEXT
John 01-MAY-09 Approval record 1 added,Approval record 2 added
David 02-MAY-09 Approval record 1 removed
SQL> 10g and up:
with t as (
select 'John' updatedby,to_date('01-May-2009','dd-mon-yyyy') updateddate,'Approval record 1 added' text from dual union all
select 'John',to_date('01-May-2009','dd-mon-yyyy'),'Approval record 2 added' from dual union all
select 'David',to_date('02-May-2009','dd-mon-yyyy'),'Approval record 1 removed' from dual
select updatedby,
updateddate,
ltrim(sys_connect_by_path(text,','),',') text
from (
select t.*,
row_number() over(partition by updatedby,updateddate order by text) rn
from t
where connect_by_isleaf = 1
start with rn = 1
connect by updatedby = prior updatedby
and updateddate = prior updateddate
and rn = prior rn + 1
order by updatedby,
updateddate
with t as (
select 'John' updatedby,to_date('01-May-2009','dd-mon-yyyy') updateddate,'Approval record 1 added' text from dual union all
select 'John',to_date('01-May-2009','dd-mon-yyyy'),'Approval record 2 added' from dual union all
select 'David',to_date('02-May-2009','dd-mon-yyyy'),'Approval record 1 removed' from dual
select updatedby,
updateddate,
ltrim(sys_connect_by_path(text,','),',') text
from (
select t.*,
row_number() over(partition by updatedby,updateddate order by text) rn
from t
where connect_by_isleaf = 1
start with rn = 1
connect by updatedby = prior updatedby
and updateddate = prior updateddate
and rn = prior rn + 1
order by updateddate,
updatedby
UPDAT UPDATEDDA TEXT
John 01-MAY-09 Approval record 1 added,Approval record 2 added
David 02-MAY-09 Approval record 1 removed
SQL> SY. -
Row with visibility expression - need to access values in other rows if present
I have a row that I added and set its visibility with an expression since I want to handle its display differently than the others in its group. So, to calculate the value I need to refer to other rows.
The report has its first column with names of the "metrics" we are reporting on.
Shoe Volume
Shoe Revenue
Shoe Revenue / Order
Its that last one that Id like to use an expression based on the other two, but that seems rather messy in SSRS.
The data comes from a stored procedure, and Im thinking thats a better place to handle this, rather than SSRS.
Is there any decent solution to this in the report with an expression?It is a little confusing... You say that you wish to hide a row in your report based on other values in the table. That is simple to do. Just use IIf statement that will return true when you want to hide the row. Something like =IIf(Fields!Other.Value =
17.7, True, False).
You say that your first column has the names of Metrics and you give three names. Are all three in a single column or is it three columns?
You also state that it is the 3rd of these that you wish to use an expression with. Does that mean that you want to hide that column and not the row? or you want to hide that column as well? Or that you want to hide this one value in the row and not the
entire row?
In any case, IIf statement is most often used for Hide expressions because an item (row, column, cell, table, etc.) is either hidden or visible... 2 states... and IIf returns a Boolean. You refer to other fields in the same scope using a Fields!Field_Name.Value
syntax so simply check if the value from the other cell meets your criteria to hide.
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek. -
Retrieve Distinct Values using XQuery
The following query is returning me duplicate rows. How can we retrieve the distinct values? Can we use Distinct somewhere in this query? Please help me.
SELECT XMLQuery('<Update>
{ for $demo in (ora:view("TableA")),
$demo_audit in ora:view("TableA_AUDIT")
let $demo_id := $demo/ROW/ID/text(),
$demo_audit_trans_date := $demo_audit/ROW/DATE/text(),
$demo_audit_id := $demo_audit/ROW/ID/text(),
$demo_audit_type := $demo_audit/ROW/TYPE/text()
where $demo_id = $demo_audit_id and
$demo_audit_type = "U"
return
<result>
<type>U</type>
<id>{$demo_id}</id>
</result>}</Data>' RETURNING CONTENT)
FROM dual;Geoff,
I tried distinct-values in both let and return; however the result isn't distinct. Is the usage correct?
SELECT XMLQuery('<Update>
{for $a in ora:view("EMP")
let $a_empno := distinct-values($a/ROW/EMPNO/text()),
$a_ename := $a/ROW/ENAME/text(),
$a_job := $a/ROW/JOB/text(),
$a_mgr := $a/ROW/MGR/text(),
$a_deptno := distinct-values($a/ROW/DEPTNO/text())
return
<op>
<empno>{distinct-values($a_empno)}</empno>
<name>{$a_ename}</name>
<deptno>{distinct-values($a_deptno)}</deptno>
</op>}
</Update>'
RETURNING CONTENT)
FROM dual;
The output generated is given below:
<Update>
<op>
<empno>1</empno>
<name>Henry</name>
<deptno>10</deptno>
</op>
<op>
<empno>1</empno>
<name>Henry1</name>
<deptno>10</deptno>
</op>
</Update> -
Group by based on sum of a column
dear all
i have a scenario that I think can't be achieved using SQL alone.
I need to group by a column while sum of another column is > 25. here is some sample data, (assuming it is sorted descending by another date field)
REGO S_NUM HRS QTY
==== ===== === ===
VHXB S1 9 15
VHXB S1 10 10
VHXB S1 7 25
VHXB S1 15 9
VHXB S1 18 18
VHXB S1 10 6
VHXB S1 12 24
VHXA S1 12 15
VHXA S1 18 10
VHXA S1 7 25
VHXA S1 12 9
VHXA S1 18 18
VHXA S1 11 6
VHXA S1 12 24
The above data should be grouped by REGO, S_NUM and the result should look like below,
VHXB S1 26 50 (first 3 rows since the sum(HRS is greater than 25))
VHXB S1 32 27 (next 2 rows)
VHXA S1 30 25
VHXA S1 37 52
any ideas how to write a pl/sql code for this ?
Thanks
Suresh NarasimhaHi, Suresh,
Welcome to the forum!
user10742238 wrote:
dear all
i have a scenario that I think can't be achieved using SQL alone.Sure you can do that in pure SQL. Below is a solution using CONNECT BY. Another approach involves MODEL, and yet another uses a recursive WITH clause (new in Oracle 11.2).
I need to group by a column while sum of another column is > 25. here is some sample data, (assuming it is sorted descending by another date field)Which column has to add up to more that 25? It looks like hrs, but don't make people guess.
REGO S_NUM HRS QTY
==== ===== === ===
VHXB S1 9 15
VHXB S1 10 10
VHXB S1 7 25
VHXB S1 15 9
VHXB S1 18 18
VHXB S1 10 6
VHXB S1 12 24
VHXA S1 12 15
VHXA S1 18 10
VHXA S1 7 25
VHXA S1 12 9
VHXA S1 18 18
VHXA S1 11 6
VHXA S1 12 24
The above data should be grouped by REGO, S_NUM and the result should look like below,
VHXB S1 26 50 (first 3 rows since the sum(HRS is greater than 25))
VHXB S1 32 27 (next 2 rows)Did you mean 33, not 32?
VHXA S1 30 25
VHXA S1 37 52So, if there's a group at the end of any rego/s_num section, and it totals 25 or less, you want to ignore that last group. Right?
any ideas how to write a pl/sql code for this ?The previous answer is right. Whevenver you have a problem, post CREATE TABLE and INSERT statements for your sample data (relevant columns only: in this case, the DATE column that determines the order is relevant) and the results you want from that data, formatted, within \ tags.
Explain how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott or hr schemas) then you don't need to post any sample data; just the results and the explanation.
Your problem is very similar to the following problem, based on the scott.emp table. The following query:SELECT deptno, ename, sal, comm
FROM scott.emp
ORDER BY deptno, ename
produces this output:` DEPTNO ENAME SAL COMM
10 CLARK 2450
10 KING 5000
10 MILLER 1300
20 ADAMS 1100
20 FORD 3000
20 JONES 2975
20 SCOTT 3000
20 SMITH 800
30 ALLEN 1600 300
30 BLAKE 2850
30 JAMES 950
30 MARTIN 1250 1400
30 TURNER 1500 0
30 WARD 1250 500
Now say we want to group consecutive rows (where "consecutive" means in order by ename, which we'll assume is unique within each deptno) such that each group has a total sal of over 3000. That is, we want these results:` DEPTNO ENAME TOTAL_SAL TOTAL_COMM
10 CLARK 7450
20 ADAMS 4100
20 JONES 5975
30 ALLEN 4450 300
30 JAMES 3700 1400
Here's one way to get those results:WITH got_analytics AS
SELECT deptno, ename, sal, comm
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY ename
) AS r_num
, SUM (sal) OVER ( PARTITION BY deptno
ORDER BY ename
) AS running_sal
FROM scott.emp
, got_grps AS
SELECT l.deptno
, l.ename
, l.r_num
, SUM (h.sal) AS total_sal
, SUM (h.comm) AS total_comm
, COUNT (*) AS cnt
FROM got_analytics l
JOIN got_analytics h ON h.deptno = l.deptno
AND h.running_sal BETWEEN l.running_sal
AND l.running_sal + 3000
+ h.sal
- l.sal
GROUP BY l.deptno
, l.ename
, l.r_num
SELECT deptno, ename, total_sal, total_comm
FROM got_grps
WHERE total_sal > 3000
START WITH r_num = 1
CONNECT BY r_num = PRIOR r_num + PRIOR cnt
AND deptno = PRIOR deptno
ORDER BY deptno, ename
Briefly, how it works is that the sub-query got_grps calculates, for each row, what the totals would be if a group started with that row. For example, in deptno=10, we know a group will start with CLARK, because taht's the first row, but we won't know if another group will begin with KING or MILLER. Got_grps assumes there will be such a group, and counts the number of rows in the group. Then, in the main query, we use that count to find where the second (and later) groups actually do begin.
Always say which version of Oracle you're using. The query above works should work in Oracle 9.1 (and higher); I tested it using version 10.2.0.1.0. -
How to count number of rows as well as the sum of a column in a procedure
Hi, i need to count the number of rows a sql returns in a procedure.
as well as i need to sum up a different column.
i need the following output:
count the number of rows output
and sum the total column
code:
procedure samba_extraction (p_errmsg IN out varchar2
,p_errcode IN out NUMBER
,p_filename in varchar2
,p_start_date varchar2
,p_end_date varchar2)
is
file_handle utl_file.file_type; -- file handle of os flat file
-- cursor to select the c_samba_resources
cursor c_samba is
select
lpad(h.contract_number,15,'0') contract_number
,h.short_description description
,h.attribute_category context_value
,h.attribute7 samba
,h.attribute8 samba_number
,h.start_date start_date
,h.end_date end_date
,h.sts_code active_inactive
,l.price_negotiated price
,l.tax_amount tax
,LTRIM(to_char((l.price_negotiated + l.tax_amount),'00000000.00')) total
from
oks_auth_headers_v h
,oks_auth_lines_v l
where h.id = l.chr_id
and ((h.start_date <= (p_end_date))
and (h.end_date >= (p_start_date)))
and h.attribute7 = 'SAMBA'
-- and h.sts_code = 'ACTIVE'
and ((h.attribute_category = 'SUBSCRIPTION.DURATION')
or (h.attribute_category = 'SUBSCRIPTION.VALUE')
or (h.attribute_category ='SUBSCRIPTION.QUANTITY'));
l_output varchar2(1000);
l_counter varchar2(11);
l_total varchar2(11);
l_filename varchar2(30);
begin
if p_filename IS NOT NULL then
-- l_batch_no := 'T';
l_filename := p_filename || '.txt';
-- open file to write into and obtain its file_handle.
file_handle := utl_file.fopen('/usr/tmp',l_filename,'W');
fnd_file.put_line(fnd_file.log,'The '|| l_filename||' file you have requested has been placed in the usr/tmp directory');
for l_info in c_samba
loop
-- l_output := null;
l_output := l_info.samba_number||'+'||l_info.total||l_info.contract_number;
utl_file.put_line(file_handle,l_output);
fnd_file.put_line(fnd_file.output, l_output);
dbms_output.put_line(l_output);
end loop;
else
p_errmsg := ('Please enter a filename for this file ');
write_log('UPDATE : ' ||p_errmsg);
end if;
-- close the file.
utl_file.fclose(file_handle);
exception
when no_data_found then
dbms_output.put_line('no_data_found');
utl_file.fclose(file_handle);
when utl_file.invalid_path then
dbms_output.put_line('UTL_FILE.INVALID_PATH');
utl_file.fclose(file_handle);
when utl_file.read_error then
dbms_output.put_line(' UTL_FILE.READ_ERROR');
utl_file.fclose(file_handle);
when utl_file.write_error then
dbms_output.put_line('UTL_FILE.WRITE_ERROR');
utl_file.fclose(file_handle);
when others then
dbms_output.put_line('other stuff');
utl_file.fclose(file_handle);
end samba_extraction;
end xx_samba;Hi,
Initialise one variable TOT_ROWS to 0.
Then in the for loop
tot_rows := tot_rows + +1 ;
so after for loop the value in the tot_rows will be the total records..
If u want it to get this value in the calling procedure of this , just declare tot_rows parameter as out parameter.
For sum of a column:
Initialise a variable sum_col to 0.
In the for loop
sum_col := sum_col+I_info.column_name
aprameter if u wish return this value as out..
I think this wil give u the o/p..
cheers,
Sivarama -
Inserting a row in a schema-based xml type column
i have problems while inserting a row in a schema-based xml type column
it reports an error(schema and elemnt do not match)
although they are matching if anyone can try it
and if it worked plz send me the exampleSQL> DESC XML_TAB;
Name Null? Type
XML XMLTYPE
SQL> INSERT INTO XML_TAB
2 VALUES
3 (xmltype('<request>
4 <filter>(extshortname=bhagat)</filter>
5 <attributes>dn</attributes>
6 <context/>
7 <scope>subtree</scope>
8 </request>'));
1 row created.
If your problem persists,post ur lines of code..
Good luck!!!
Bhagat -
Select records based on first n distinct values of column
I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.
eg:
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
7 lmn 10
so on... (till some count)
Result should be
Query 1 should result --->
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
query 2 should result -->
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
query 3 should result -->
7 lmn 10
9 .. ..
so on..
How to write a query for this inside a loop.Hi,
So, one group will consist of the lowest id value, the 2nd lowest and the 3rd lowest, reggardless of how many rows are involved. The next group will consist of the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you need to assign numbers 1, 2, 3, 4, 5, 6, ... to the rows in order by id, with all rows having the same id getting the same number, and without skipping any numbers.
That sounds like a job for the analytic DENSE_RANK function:
WITH got_grp_id AS
SELECT id, name, age
, CEIL ( DENSE_RANK () OVER (ORDER BY id)
/ 3
) AS grp_id
FROM table_x
SELECT id, name, age
FROM got_grp_id
WHERE id = 1 -- or whatever number you want
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
See the forum FAQ {message:id=9360002} -
Summing the Rows and Columns in an Array
I am importing a 2-dimensional array of integers.(which is held in a 2-dimensional array)
I need to store the row sums and column sums in separate 1-dimensional arrays.
I can get the integers in and print out a list along with the grand total(sum of all).
But, how do I pass each row's and each column's value in to my sumRow and sumCol methods to get the sum for each row and each column?
Can I do the row and column summing in the same "for" statement where I calculate the "grand total"? Or am I making this more difficult than it is?
Would appreciate any help.
This is what I have so far:
import java.awt.Graphics;
import java.applet.Applet;
public class TwoWayTable extends Applet {
int numRows;
int numCols;
int [] [] cell;
int [] rowSum;
int [] colSum;
int grandTotal;
public TwoWayTable(int [][] data){
grandTotal = 0;
cell = new int [data.length][data.length];
for(int i = 0; i < data.length; i++)
for(int j = 0; j < data.length; j++){
cell[i][j] = data[i][j];
grandTotal += cell[i][j];
System.out.println(cell[i][j]);
System.out.println(grandTotal);
public int sumRow(int [] data2){
int rowaccumulator=0;
rowSum = new int[data2.length];
for(int numRows = 0; numRows < rowSum.length; numRows++){
rowaccumulator += rowaccumulator + rowSum[numRows];
return(rowaccumulator);
public int sumCol(int [] data3){
int colaccumulator = 0;
colSum = new int[data3.length];
for(int numCols = 0; numCols < colSum.length; numCols++){
colaccumulator += colaccumulator + colSum[numCols];
return(colaccumulator);Thanks for your input.
I'll make the changes that you suggest.(after this)
My output prints:
4 6 3 8 21
9 1 5 3 18
13 7 8 11 39
numbers are right, but I need to format the table
the output needs to look like this:
int int int int | rowsum
int int int int | rowsum
colsum colsum colsum colsum | total
How do I do this?
I have no idea?
I'm supposed to call a "void setMargins( )" method to line this up, without
using the exotic formatting in the IO library.
I'm also supposed to use "public String toString( )"
This is what I have so far:
import java.awt.Graphics;
import java.applet.Applet;
public class TwoWayTable extends Applet {
int numRows;
int numCols;
int [] [] cell;
int [] rowSum;
int [] colSum;
int grandTotal;
public TwoWayTable(int [][] data){
cell = new int [data.length][data.length];
for(int i = 0; i < data.length; i++){
for(int j = 0; j < data.length; j++){
cell[i][j] = data[i][j];
calcTotals(cell);
for(int i = 0; i < cell.length; ++i){
for(int j = 0; j < cell.length; ++j){
System.out.print(cell[i][j] + " ");
System.out.println(rowSum[i] + " ");
for(int j = 0; j < cell.length-1; ++j){
System.out.print(colSum[j] + " ");
System.out.println(colSum[cell.length-1] + " " + (grandTotal));
public void calcTotals(int [][] data2){
grandTotal = 0;
rowSum = new int[data2.length];
colSum = new int[data2.length];
for(int numRows = 0; numRows < data2.length; numRows++){
for(int numCols = 0; numCols < data2.length; numCols++){
grandTotal += data2[numRows][numCols];
rowSum[numRows] += data2[numRows][numCols];
colSum[numCols] += data2[numRows][numCols]; -
SSRS 2012
Dataset (40 columns) including the first 3 rows for Report layout configuration (eg: the <second> row specifies the column background color).
Starting from the 4th row, the dataset contains data to be displayed.
I would like to change the background color of the ColumnHeader/Column based on the value in the same column in the <second> row.
How can I accomplish the this requirement? (this must be applied for all the columns)
ThanksHi Fasttrck2,
Per my understanding that you want to specify the background color of all the columns/column header based on the value in one special column of the special row, right?
I have tested on my local environment and you can add expression to condition show the background color in the columns properties or the column header properties.
Details information below for your reference:
Specify the background color in the Column header: you can select the entire column header row and in the properties add expression in the Background color :
If you want to specify the background color for the entire column, you can select the entire column and add the expression, repeat to add background color for other columns.
If you want to specify the background color based on the value in the specific columns and row, you can create an hidden parameter to get the list of values from the specific column, specify the Available values and default values by select "Get
values from a query", finally using the expression as below to get the specific value you want:
Expression(Backgroud Color):
=IIF(Parameters!Para.Value(1)="1221","red","yellow")
If your problem still exists, please try to provide some smaple data of the report and also the snapshot of the report structure to help us more effective to provide an solution.
Any problem, please feel free to ask.
Regards
Vicky Liu
If you have any feedback on our support, please click
here.
Vicky Liu
TechNet Community Support -
Highlight row in standard report based on value in column...
I am trying to highlight rows of a standard report based on the value of the column TICKET_TYPE.
I have been following the post: Highlighting a ROw in a tablular form based on a column in the row
but having difficulty. I receive the following error:
ORA-06550: line 1, column 34: PLS-00201: identifier 'SHRIMP' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored
ERR-1025 Error processing PLSQL expression. SHRIMP = 'SHRIMP'
My report query is:
select T.TRIP_ID,
T.TRIP_ID trip_show,
T.TRIP_ID trip_select,
T.DAYS_AT_SEA,
T.NBR_OF_CREW,
T.TRIP_START_DATE,
T.VESSEL_ID,
o.ticket_type ticket_type
from TRIPS T, one_ticket_type o
where t.dea_permit_id = :G_DEA_PERMIT_ID and t.trip_id = o.trip_id
I have created a new template called one-ticket-highlight.
row tempate 1 = <td #ALIGNMENT# headers="#COLUMN_HEADER#" class="t14data" style="background:red">#COLUMN_VALUE#</td>
row template 1 condition = use based on pl/sql expression
row template 1 expression = #TICKET_TYPE# = 'SHRIMP' (**** I have also tried without the quote)
any thoughts? thanks!!
Edited by: KEH813 on May 25, 2010 11:10 AMHi,
You can achive the same using javascript without changing the page template.
http://apex.oracle.com/pls/apex/f?p=27576:8
here is the code for the same
<style>
.myclass{ background-color:red;text-align:center}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js "></script>
<script>
$(function(){
$("td [headers='DEPTNO']").each( function(i){
if($(this).html() == $v('P8_DEPTNO')) //value of the textfield
ele = $("td [headers='ENAME']").eq(i)
ele.removeClass('t20data'); //i'm using theme 20 so t20data .. u need to change this part
ele.addClass('myclass');
</script>Regards,
Shijesh -
Table -- sum of rows and columns?
I was wondering if anyone has a suggestion to how I can easily generate the sum of each row and column in a two dimensional table? This is what I've got so far:
public class SumRowsColumns {
public static void main (String[] args) {
int[][] table = new int[2][3];
// gets the values
for (int i = 0; i < table.length;
i++) {
for (int j = 0; j < table.length;
j++)
table[i][j] = Terminal.lesInt(); // Terminal is a class that can read the terminal input
System.out.println("\t\t\t\tSum:");
// prints the values
for (int i = 0; i < table.length;
i++) {
for (int j = 0; j < table[i].length;
j++) {
System.out.print("\t" + table[i][j]);
System.out.println();
// sum of first column
int sumColumn = 0;
for (int i = 0; i < table.length;
i++) {
sumColumn += table[i][0];
System.out.print("\nSum:\t");
System.out.println(sumColumn);
Example of output:
1
2
3
4
5
6
Sum:
1 2 3
4 5 6
Sum: 5This is the output I'd like:
1
2
3
4
5
6
Sum:
1 2 3 6
4 5 6 15
Sum: 5 7 9One way of getting the sum for all the columns is to make a for-loop for each one of them, but there has to be a better way. I could apply the same hack to get the sum of the rows, but I still wouldn't know how to get the layout I want.After many hours of frustration I finally solved it (for-loops can be confusing, man) after I got a hint from a post in another forum: http://www.linuxquestions.org/questions/showthread.php?postid=624021#post624021
A more logical name to the integers actually helped a lot too. And here's the final product:
public class SumRowsColumns {
public static void main (String[] args) {
int[][] table = new int[2][3];
// gets the values
for (int row = 0; row < table.length;
row++) {
for (int col = 0; col < table[row].length;
col++)
table[row][col] = Terminal.lesInt(); // Terminal is a class that reads the terminal input
System.out.println("\t\t\t\tSum:");
// prints the values and sum of each row
for (int row = 0; row < table.length;
row++) {
for (int col = 0; col < table[row].length;
col++) {
System.out.print("\t" + table[row][col]);
int sum = 0;
for (int col = 0; col < table[0].length;
col++) {
sum += table[row][col];
System.out.println("\t" + sum);
System.out.print("\nSum:");
// sum of each column
for (int col = 0; col < table[0].length; // table[0].length is the length of row 0 (the number of columns)
col++) {
int sum = 0;
for (int row = 0; row < table.length; // table.length is the number of rows
row++) {
sum += table[row][col];
System.out.print("\t" + sum);
System.out.println();
} -
Sum calculated rows and columns
I have written a SQL report to count the number of offenses by levels of disciplinary actions. Now I want to total
the counts for the rows and columns. How do I do this? Below is my code. It produces column headings with counts. Ie.
Offense Description Level I Level II Susps Terms
2 Minor Violations 0 1
0 0
SELECT
UPPER(DESCRIPTION) as OFFENSE,
SUM(CASE
WHEN OUTCOME = 'LEVEL I'
THEN 1
ELSE 0
END) as LEVELI,
SUM(CASE
WHEN OUTCOME = 'LEVEL II'
THEN 1
ELSE 0
END) as LEVELII,
SUM(CASE
WHEN OUTCOME = 'SUSPEND'
THEN 1
ELSE 0
END) as SUSPEND,
SUM(CASE
WHEN OUTCOME = 'TERM'
THEN 1
ELSE 0
END) as TERM
FROM
PAGRDI
Where
R_DATE >= '2014-01-01' and R_DATE <= '2014-01-31'
Group by
DESCRIPTION
Order by
OFFENSEHi Wildcatgirl,
According to your description, you have used T-SQL to get the counts for different OUTCOME. Now you want to get the total for each OFFENSE and OUTCOME. Right?
In this scenario, since you have already get those counts with T-SQL query, so in your dataset it will have data fields below: OFFENSE, LevelI, LevelII, SUSPEND, TERM. We just need to drag these data fields into a table, add a column at the end of the table
and use expression to sum the counts for different OUTCOME. Then we can add a total for the detail row. We have tested this scenario in our local environment. Here are screenshots for your reference:
Reference:
Tables (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
Populate multiple rows and columns based off of a single cell
Does anyone know a way to populate multiple rows and columns based off of the input of a single cell. I'm trying to create a workout tracker that auto populates from a master list of workouts. Example, in A2 the user selects the workout from a drop down menu (St1, St2, St3, etc) and the workout is pulled from the master list and is populated into B2:C5.
I'm using =LOOKUP(A2,Master :: A2:A32,Master :: C2:C32) right now, but it's only drawing the top column. I'm looking for an edit for the formula (or completely new formula) that will place the info from the 1st column of the Master table into the 1st column of the Auto Tracker 1 table and then on down until the 4th column.
Here is a screen shot of what I have now:
And an example of what I'd like to accomplish:
Any and all help is appreciated, and please let me know if there is any more info that I can give that'd help out.Hi Mike,
Your screenshots show that you have merged some cells in Column A of both tables. That may be the reason why the LOOKUP function is having trouble working out which range of cells to examine.
Hope this helps.
Regards,
Ian.
Maybe you are looking for
-
GR Reversal allowed inspite of Invoice Payment
Hello, We have GR reversal allowed inspite of Invoice Payment being carried out. The GR Revresal flag for Mvt type 102 is not set. However this particluar example does not have the GR based IV flag set in the PO. I am assumig this is the reason for
-
Multiple SubVI display onto main VI
Hi everyone, Probably a really simple solution to this problem: I have 6 SubVI's that I want to use on one main VI, no problem, but I would like to display all 6 SubVI front panel display onto this one main VI. Hope this makes sense! I looked at SubP
-
Why does Premiere Pro stop, or drop frames when using the Timecode Effect.
The Timecode Effect is gpu accelerated, the render bar is yellow and it still drops frames. If it drops frames on a yellow bar, how can I ever trust it to print to tape? It wouldn't be a problem if I could say render the yellow sections of my edit, b
-
My iTunes installation via Windows 7 does not install the Apple Mobile Device Support file
I have followed several suggestions to resolve the problem caused because of my update of iTunes does not install the Apple Mobile Device Support folder, thus making it impossible for me to sync my iPhone 4S to my desktop version of iTunes. I have tr
-
Web.xml Backup copy location
Before I make changes to web.xml files I make a backup copy, (webbackup.xml). Does it matter if this backup file is saved in the same folder location as the web.xml that is being changed? I've been told by some people to save the backup in a differen