Counter in Query
Hi all,
I need to create a counter that counts the sales order items per sales order. For example Sales Order 00001 has 5 line items. I need the counter to show "5" in all five rows for that sales order. I have Sales Order Number & Sales Order Item in the InfoCube.
Desired Output:
Sales Order SalesOrderItem Counter
00001 10 5
00001 20 5
00001 30 5
00001 40 5
00001 50 5
Cheers
may be you try this
1) create a calculated key figure ,, with value 1
2) remove the supress result row from the sales order line items..
3) create another calculated key figure which will be SUMCT (calculated key figure 1)
Your result should like below
Salorer Oder- lin-item qty number
0001 0001 100 3
0002 200 3
003 100 3
Result 400 9
0002 1001 100 3
1002 200 3
1003 100 3
Result 400 9
Similar Messages
-
Hi Experts,
There is a problem in my query output.
I have a CKF for sales documents number created with replacement path which gives the correct count of number of Sales documents.
But the req here is to create two more counters which will be counting the passed and failed count with reference to other KF1 (the value of this KF can be 0 or 1).
i.e. If the KF1 value is then failed count would be 1 .
else passed count would be 1.
I have used the Replcement path variable created for Sales Document count.
For failed count the CKF formula which I have created is: (Sales Order Count ) * (KF1<>1)
Which gives the right result but as soon as I remove the drill down , instead of aggrading the total results, failed counter still shows 1 which is incorrect.
Could any one please help me out.
Regards,
BW Userhello,
try using exception aggregation as total and reference char as the one which u have reomved from drilldown.
Regds,
Shashank -
Hello all,
How can i get total number of count in the below query...its always giving 1 for each rows..
Cover countofcovers
12345 1
43564 1
43535 1
i need 3 as count ..any help
select cover,count(*) countofcovers from ( SELECT A.COVER_NUMBER cover
FROM HL01unit.COVER A,
HL01unit.CLIENT_STAGING G,
HL01unit.COVER_CATEGORY F
WHERE A.POLICY_NUMBER ='10000142'
AND F.COVER_NUMBER = A.COVER_NUMBER
AND G.POLICY_NUMBER = A.POLICY_NUMBER
AND G.COVER_NUMBER = A.COVER_NUMBER
AND A.PARENT_COVER_NO IS NULL
AND UPPER(G.SURNAME) LIKE UPPER(RTRIM('R')) CONCAT '%'
UNION
SELECT DISTINCT(A.PARENT_COVER_NO) cover
FROM HL01unit.COVER A,
HL01unit.CLIENT_STAGING G,
HL01unit.COVER_CATEGORY F
WHERE A.POLICY_NUMBER ='10000142'
AND F.COVER_NUMBER = A.COVER_NUMBER
AND G.POLICY_NUMBER = A.POLICY_NUMBER
AND G.COVER_NUMBER = A.COVER_NUMBER
AND A.PARENT_COVER_NO IS NOT NULL
AND UPPER(G.SURNAME) LIKE UPPER(RTRIM('R')) CONCAT '%'
) yTable group by covertry union all instead of union
Peter
maybe a small example to explain that the inner query is
wrong and not the group by
select 1 counter from dual;
COUNTER
1
1 row selected.
select counter, count(*) from (
select 1 counter from dual
union
select 1 counter from dual)
group by counter;
COUNTER COUNT(*)
1 1
1 row selected.
select 1 counter from dual
union all
select 1 counter from dual;
COUNTER
1
1
2 rows selected.
select counter, count(*) from (
select 1 counter from dual
union all
select 1 counter from dual)
group by counter;
COUNTER COUNT(*)
1 2
1 row selected.
Message was edited by:
Peter Verhaegen -
Hi
i have a table with about 60 million rows and growing.(10gR2 linux x86)
a query of the max value and the count number of rows in the table takes at least 30 seconds even when doing a fast index scan.
is there any way to do things better ?
10x,
doronhow do you have the information that "N BETWEEN 83289905 AND 83289955" returns the last 50 rows form the table?
I think you may compare this rank analytic function's results;
SELECT t.*
FROM (SELECT e.*, rank() over(ORDER BY ttime DESC) AS rank
FROM event e
WHERE CATEGORY = 'Alarms') t
WHERE rank <= 50
you may use sql*plus and compare the responce times and blocks read in memory and disk;
set timing on
set autotrace traceonly
alter system flush buffer_cache; -- this is to prevent caching affect, use it if this is a test system of course
-- your query
alter system flush buffer_cache; -- this is to prevent caching affect, use it if this is a test system of course
-- query to compare -
I have the following record in InCube:
Vendor...PO Date.....Counter
AAA......18/10/2011..1
BBB......18/10/2011..1
AAA......19/10/2011..1
AAA......20/10/2011..1
AAA......21/10/2011..1
BBB......21/10/2011..1
In my query, I want to count number unique PO Date, which is 4 (18/10/2011, 19/10/2011, 20/10/2011, 21/10/2011)
Is it possible? How can I do that???
Thanks.Hi,
Thanks for all your input. I have tried that:
Create one CKF as Count - Exception Aggregation as Count - With reference to PO DATE
But I have 6 as a result, which is wrong. I want to cout based on unique PO Date.
In my following example, I should have 4 as result:
I have the following record in InCube:
Vendor...PO Date.....Counter
AAA......18/10/2011..1
BBB......18/10/2011..1
AAA......19/10/2011..1
AAA......20/10/2011..1
AAA......21/10/2011..1
BBB......21/10/2011..1
In my query, I want to count number unique PO Date, which is 4 (18/10/2011, 19/10/2011, 20/10/2011, 21/10/2011)
Is it possible? How can I do that??? Please help.
Thanks. -
Help with "distint count" in query
Hi
I have a query that returns the following error:
ORA 00936: Missing Expression
and also after running it again
I get ORA 00900: Invalid SQL statement.
The query is as follows:
SELECT
DISTINCT student_id,
COUNT(student_id),
ABSENCE_REASON_CODE,
calendar_date,
attendance_status,
FROM AT_HOURLY_ATTENDANCE_RECORDS
WHERE (absence_reason_code = 'UC')
OR (absence_reason_code = '1');all help is gratefully acknowledged. Thanks in advanceHi
Thanks to both guys for helping me out.. (Steven and Gasparatto)
The query still has the following problem:
ORA-00900: invalid SQL statement
I wonder why this is happening..
(Toad is pointing out student_id as a possible culprit
the code again is:
SELECT
DISTINCT student_id,
COUNT(student_id),
ABSENCE_REASON_CODE,
calendar_date,
attendance_status
FROM AT_HOURLY_ATTENDANCE_RECORDS
WHERE (absence_reason_code = 'UC')
OR (absence_reason_code = '1');Please excuse me for my naive questions. I have learnt a lot today itself. Thanks a lot again -
Realize Counter in Query without drill-down
Hello to everybody,
I have got a query which is displaying POS data for different subsidiaries. In the rows is the subsidiary-number and the sales slip number. In the columns I have a counter as key figure, which shall count the number of existing sales slips. This works well, when I drill-down to the sales slip number and the correct number of sales slips is displayed as result at the last row of the key figure.
But I do not want every sales slip to be displayed, so I remove it from the drill-down, with the effect that the counter always shows "1" as result.
How can I make the counter work without having the sales slip in the drill-down?
Thank you very much!
PS: Sorry in advantage, if my English is bad, but I am from Germany.I think I do now know the problem: the counter I use is a calculated key figure. There is a restricted key figure which counts the number of positions on each sales slip. This key figure is used to realize a calculated key figure which counts the number of sale slips by division of the number of positions by itself, which results in "1" for each sales slip. But of course for the result row it also shows "1", because at the result row there must be used a summation and not a division.
Example:
position...........sales slip
counter............counter (position counter / position counter)
4....................1
6....................1
3....................1
7....................1
=============
20..................1 (because it calculates 20/20 and not 111+1)
Any idea how to solve this? Thanks! -
919: Column count replaces query count when opening table/view/etc tab
I don't know whether this is intentional or not, but I have just noticed that opening a table or view tab from the connection pane replaces the existing query count message with the query count from the column query. For example, opening a table tab for a table with 14 columns sets the query count message to "All Rows Fetched: 14".
This is not a big issue, but adds to the aggravation of only having the latest query count message, rather than one for each SQL Worksheet.
Is it possible to find somewhere on the SQL Worksheet that we can put it's query count message (for example to the right of the execution time)?I am happy for querying the columns of a table/view/etc to display the fetch count of the columns, although I am rarely interested in how many columns there are in a table/view/etc.
However, I already find it frustrating that the query count is only for the last fetch - it can be very useful having the query count for last fetch per SQL Worksheet. Having the last fetch overwritten by opening a table tab only makes it more frustrating. -
Hi All.
I was trying to write a query for below result set but can not figure out if i can achieve below result set through T-SQL.
Emplid FunctionId Count
1 2
1 3 1
1 4 2
1 4
1 5 3
1 6 4
1 3
2 3
2 3
2 1 1
2 2 2
Description
When an Employee is changing from job/function, am struggling to get incremental number / count for that employ based on no. of funtionid changed.
I need a count only when an employee is going to do something else (another function).
The example above is showing how the count output should be.
am not sure it i need to use any analytical function, any help would be appreciated.
and many thanks in advance for reading my questionSomething like
SQL> ed
Wrote file afiedt.buf
1 with x as (
2 select 1 empid, 2 functionid, sysdate dt from dual union all
3 select 1, 3, sysdate+1 from dual union all
4 select 1, 4, sysdate+2 from dual union all
5 select 1, 4, sysdate+3 from dual union all
6 select 2, 3, sysdate+4 from dual union all
7 select 2, 3, sysdate+5 from dual union all
8 select 2, 1, sysdate+6 from dual
9 )
10 select empid,
11 functionid,
12 sum(case when functionid = prior_functionid
13 then 0
14 else 1
15 end) over (partition by empid
16 order by dt)-1 cnt
17 from (
18 select empid,
19 functionid,
20 lag(functionid) over (partition by empid
21 order by dt) prior_functionid,
22 dt
23 from x
24* )
SQL> /
EMPID FUNCTIONID CNT
1 2 0
1 3 1
1 4 2
1 4 2
2 3 0
2 3 0
2 1 1
7 rows selected.appears to work
Justin -
Hi All
I have 2 queries, query A and query B between these queries in tcode RSBBS i have created a report to report link. Query A shows summarised car mileage data such as total miles and total cost, while query B shows more detalied info about the milegae such as trave location travel reason etc. The report to report works fine as the user can right click from a line from query A and go to to query relating to that line in Query B with the more detailed data.
Now i want to create a document counter that will count how many records in query B, the problem i am facing is that because Query A and Query B are based on different infoprovider, when I am creating my formula variable in reference characteristic i cannot select the info object i need to count the lines because of the fact they are based on different info provider.
Does anyone have any workarounds on how i could achive this.
regards
ForhadHi,
You can create a multiprovider on the two info providers.
-Vikram -
if i want to determine the portion of Direct Debit customers of all active customers. Can you please confirm the sql is correct
SELECT
(dd_count / all_count * 100)
FROM
SELECT
COUNT (DISTINCT c.advertiser_id) dd_count
FROM customers c
,account a
WHERE c.Advertiser_Id = a.Advertiser_Id
AND c.Advertiser_Status = 'A'
AND a.Payment_Method = 'DD'
union
SELECT
COUNT (DISTINCT c.advertiser_id) all_count
FROM customers c
,account a
WHERE c.Advertiser_Id = a.Advertiser_Id
AND c.Advertiser_Status = 'A'
AND a.Payment_Method != 'DD'
); Edited by: ricard888 on 24/01/2012 15:48Hi,
ricard888 wrote:
if i want to determine the portion of Direct Debit customers of all active customers. Can you please confirm the sql is correct
SELECT
(dd_count / all_count * 100)
FROM
SELECT
COUNT (DISTINCT c.advertiser_id) dd_count
FROM customers c
,account a
WHERE c.Advertiser_Id = a.Advertiser_Id
AND c.Advertiser_Status = 'A'
AND a.Payment_Method = 'DD'
union
SELECT
COUNT (DISTINCT c.advertiser_id) all_count
FROM customers c
,account a
WHERE c.Advertiser_Id = a.Advertiser_Id
AND c.Advertiser_Status = 'A'
AND a.Payment_Method != 'DD'
); Edited by: ricard888 on 24/01/2012 15:48Run this query:
SELECT *
FROM
SELECT
COUNT (DISTINCT c.advertiser_id) dd_count
... -- the rest exactly as you posted itto see what columns are available in the main query. -
Not able to calculate the count in Query
Hi Experts,
I have 2 cubes in a multi provider in which
Cube 1 has Work Order, Order Types, Status etc..
Cube 2 has Order type, Actual hours (Key figure)...
Now i want to calc the "Count of Actual hours work from all the work orders, with Order Type XXXX and with status XXXX.
Now i need to calc the total number of hours based upon the selection, For this, i have built a structure in Keyfigures section, but its not displaying any values in that.
Please some one help me out how to calculate this.... PLease reply me ASAP as this is a high priority requirement.
Will assign points for helpfull answers.
Thanks in Advance,
Chintu..Dear Chintu
If u r working on BI 7.0 then create Infoset using both the cubes (its not available in 3.X). Because, Infoset create a join whereas Multiprovider is used to create a Union of two or more object.
Assign point if it helps. -
Creating count from queried fields
Post Author: John
CA Forum: Formula
Hello all. Newbie here to the forum and CR.
Running CR 9
I have a report that extracts certain data from the database. A field that displays "test code", is not part of the original search criteria. I have been asked to total "test code" but, I don't know how to count the records from the extracted data.
For example, I'm pulling in everyone with a last name that begins with a "J" and who came in the store from 01/01/07 - 01/31/07. I then list the data and also print their address, city, state, zip, and "test code". The "test code" is one of 3 possible codes. I want to have 1 running total for each of these 3.
My knowledge allows me to create a running total on the field but, the total is from ALL of the records that match.
So, if we had 45 people with "J" and 01/01/07 - 01/31/07, the running total will be 67 because it is finding all data sets that match it's code. It isn't pulling from the original search criteria of "J" and 01/01/07 - 01/31/07.
Any help is appreciated.
JohnPost Author: yangster
CA Forum: Formula
A running total runs along side the data so it should never be placed in a header or the detail section.It must always reside in a group footer, page footer or report footer.Your basic running total in crystal will initilize at the report header, evaluate at the detail level and display the value in the report footer.So for your generalized case you have a simple running total that starts a count at 0 to start the report.You running total should be setup like thisField to summarize -> Product_IDType of summary -> countEvaluate - using formula -> inside formula typed in (if product_id = 4344211 then true else false)Reset -> neverAnd it won't matter if you put it in the GF2, GF1, PF, or RF the value will always be 4. If your report spans multiple pages though you should not put the formula in the PF as it report the running total as of the page but keep on totaling to the next page.My suggestion to you would be to test your report with a manual running total to see exactly where your numbers counting is going astray.To do that create 3 formulas@init_count (place in report header)whileprintingrecords;numbervar a;a:= 0@eval_count (place at the detail level)whileprintingrecords;numbervar a;if product = 4344211 thena := a + 1@display_count (place in the report footer)whileprintingrecords;numbervar a;athis will show you exactly what is being counted for every single item in your reportnormally you'd use a manual running total to get a summary of a summary or to sum a value at a group level but this should help you decode what is causing you buggy datahope this helps -
Stuck on Count Sub Query [ SOLVED ]
A Purchase Order can be receipted in Oracle.
I am using 4 tables here:
po_headers_all - Stores Purchase Order Details
po_lines_all - Stores Purchase Order Line Details
rcv_shipment_lines - Stores Receipt Line Details
rcv_shipment_headers - Stores Receipt Header Details
This simple SQL shows that a PO with 3 lines has been receipted:
SELECT pha.segment1
, rsh.receipt_num
, rsh.shipment_header_id
, rsl.shipment_line_id
FROM po.po_headers_all pha
, po.po_lines_all pla
, po.rcv_shipment_lines rsl
, po.rcv_shipment_headers rsh
WHERE pha.po_header_id = pla.po_header_id
AND rsl.shipment_header_id = rsh.shipment_header_id
AND pla.po_line_id = rsl.po_line_id
AND pha.segment1 = 1442060;
SEGMENT1 RECEIPT_NUM SHIPMENT_HEADER_ID SHIPMENT_LINE_ID
1442060 526312 583092 1285161
1442060 526312 583092 1285162
1442060 526312 583092 1285163Because the PO has 3 lines, and each line has been receipted, there is a corresponsing receipt line in the 'rcv_shipment_lines' table.
I am trying to work out a way to list a PO number, and do a count of how many times that PO has been receipted.
In the above example, the PO has 3 lines, but it has only been receipted once, because all 3 receipt lines share the same Receipt Number.
I have tried this:
SELECT pha.segment1
, (SELECT (COUNT(*))
FROM po.rcv_shipment_lines rsl
, po.rcv_shipment_headers rsh
WHERE pha.po_header_id = pla.po_header_id
AND rsl.shipment_header_id = rsh.shipment_header_id
AND pla.po_line_id = rsl.po_line_id) ct
FROM po.po_headers_all pha
, po.po_lines_all pla
WHERE pha.po_header_id = pla.po_header_id
AND pha.segment1 = 1442060;
SEGMENT1 CT
1442060 1
1442060 1
1442060 1But clearly that fails because it is counting the fact that each PO line has been receipted and has a corresponding line in the 'rcv_shipment_lines' table.
I can't just join the 'po_headers_all' table to the 'rcv_shipment_lines' table, but have to join via the 'rcv_shipment_lines' table, - the only join is:
'rcv_shipment_lines' joins 'rcv_shipment_lines' via 'shipment_header_id'
And then join the 'rcv_shipment_lines' table to the 'po_lines_all' table, and from there to the 'po_headers_all' table.
I am sorry if I am making a hash of explaining what I am trying to do.
I can supply the table definitions if required, but I haven't done so to start with because it'll make this post even longer.
Thank youThanks Dave. This is the result:
SQL> SELECT pha.segment1
2 , (SELECT COUNT(DISTINCT receipt_num)
3 FROM po.rcv_shipment_lines rsl
4 , po.rcv_shipment_headers rsh
5 WHERE pha.po_header_id = pla.po_header_id
6 AND rsl.shipment_header_id = rsh.shipment_header_id
7 AND pla.po_line_id = rsl.po_line_id) ct
8 FROM po.po_headers_all pha
9 , po.po_lines_all pla
10 WHERE pha.po_header_id = pla.po_header_id
11 AND pha.segment1 = 1442060;
SEGMENT1 CT
1442060 1
1442060 1
1442060 1I though then I could do a join via the PO_HEADER_ID instead of going via the po_line_id, and... it works! THANK YOU very much for your help. This forum is such a big help.
This works, in case you are interested:
SELECT pha.segment1
, (SELECT COUNT(DISTINCT receipt_num)
FROM po.rcv_shipment_lines rsl
, po.rcv_shipment_headers rsh
WHERE rsl.shipment_header_id = rsh.shipment_header_id
AND pha.po_header_id = rsl.po_header_id) eek
FROM po.po_headers_all pha
WHERE pha.segment1 = 1442060;Removed 'pha.po_header_id = pha.po_header_id'! -
Invalid SQL generated for count query.
A SQL statement was generated with the table name information missing when
a count SQL query was issued (e.g. SELECT COUNT(*) FROM WHERE <SOME
EXPRESSION>). The same query worked fine before switching to vertical
class mapping.
Basically no queries work with the result set to "count(this)". The
temporary work-around was to retrieve the collection and get the size. I
would rather not have to do this.
Any ideas?Brendan,
What version of Kodo is this happening with? Can you send a test case
demonstrating this to [email protected]?
-Patrick
Brendan Brothers wrote:
A SQL statement was generated with the table name information missing when
a count SQL query was issued (e.g. SELECT COUNT(*) FROM WHERE <SOME
EXPRESSION>). The same query worked fine before switching to vertical
class mapping.
Basically no queries work with the result set to "count(this)". The
temporary work-around was to retrieve the collection and get the size. I
would rather not have to do this.
Any ideas?
Maybe you are looking for
-
Connecting Wahoo Blue HR with iPhone 5 does not work, tried everything possible
Connecting Wahoo Blue HR with iPhone 5 does not work, tried everything what I could find in the interenet as solution??????
-
HT1414 What if the device is not showing up in i-tunes when I try to restore?
My i-phone 4 has gone dead and I can't restore it by hard re-set nor by going to i-tunes as the phone device is not showing up. Am i looking in the wrong place?
-
How do i customize a pricing condition?
currently i have a condition for calculating surcharge of 5%, as of now this condition is taking the amount from PB00 and calculate the 5% amount. however, i have freight costs in the line item as well, how do i configure the surcharge condition so t
-
Can't see phone memory capacity status
I changed my Nokia 3500c mobile security code from default 12345 to a new one. Then I set phone's security level to memory. After restarting the phone I changed phone security level to phone. Then I tried to see the status of my phone contacts/addres
-
Help! My G4 freezes!!
My QS2002 "freezes" from time to time. It just stops. Sometimes when I work, sometimes when it's idle. I get this from the log (Swedish Mac OS version): Storlek: 1.19 K Senast ändrad: 2007-02-27 19.46 Plats: /Library/Logs/Console/gunnar/console.log I