Query to calculate profit
Helo experts
the Above query i am using to calculate the profit based on sale and purchase price but the problem which i am facing is it includes the credit memo invoice also ...According to my need i only want those invoice whose credit memo is not made means those are not cancelled . pls update this query according to my need ........
SELECT T0.[ItmsGrpCod] as grpcode,
MAX (T1.ItmsGrpNam) as GroupName,
I1.DocNum as docnum,I1.doctype as doctype , D0.CardCode as cardcode ,
MAX ( D0.CardName ) as Name ,
D1.ItemCode as 'itmcode' , D1.ocrcode as [Branch] ,
E1.firstname as [Owner Name] ,
max ( D1.Dscription ) as Descp ,
sum ( D1.Quantity ) as Quantity ,
Sum ( D1.StockPrice ) * sum ( D1.Quantity ) as [Purchase Price] ,
sum ( D1.Price ) * sum ( D1.Quantity ) as [Sales Price] ,
(sum ( D1.Price ) * sum ( D1.Quantity )) - (Sum ( D1.StockPrice ) * sum ( D1.Quantity )) AS [Actual Proft / Loss]
from ODLN D0 , DLN1 D1 INNER JOIN OITM T0 ON D1.ItemCode = T0.ItemCode INNER JOIN OITB T1 ON T0.ItmsGrpCod= T1.ItmsGrpCod, OHEM E1 , OINV I1
where
D0.Docentry = D1.Docentry and D1.ownercode = E1.empid
and D1.TrgetEntry = I1.DocEntry and I1.doctype = 'I' and upper( D1.[Dscription]) not like upper('%Debit%')
And I1.TaxDate BETWEEN CASE WHEN [%0] = '' THEN '01/01/1900' ELSE [%0] END AND CASE WHEN [%1] = '' THEN GETDATE() ELSE [%1] END
Group By I1.DocNum, D0.CardCode , T0.[ItmsGrpCod],D1.ItemCode,D1.ocrcode , E1.firstname ,I1.doctype
union all
SELECT '' as grpcode ,
'no' as GroupName,
I1.DocNum as docnum,I1.doctype as doctype , I1.CardCode as cardcode ,
MAX ( I1.CardName ) as Name ,
' ' as itmcode , I2.ocrcode as [Branch] ,
E1.firstname as [Owner Name] ,
max ( I2.Dscription ) as Descp ,
sum ( I2.Quantity ) as Quantity ,
' 0' as [Purchase Price] ,
sum ( I2.linetotal) as [Sales Price] ,
sum ( I2.linetotal) AS [Actual Proft / Loss]
from OHEM E1 , OINV I1 ,inv1 I2
where
I1.[DocEntry] = I2.[DocEntry] and I2.ownercode = E1.empid and upper( I2.[Dscription]) not like upper('%Debit%')
and I1.doctype = 'S'
And I1.TaxDate BETWEEN CASE WHEN [%0] = '' THEN '01/01/1900' ELSE [%0] END AND CASE WHEN [%1] = '' THEN GETDATE() ELSE [%1] END
Group By I1.DocNum, I1.CardCode , I2.ocrcode , E1.firstname,I1.doctype
Regards
saurav Gupta
Hi Saurav..........
SELECT T0.ItmsGrpCod as grpcode,
MAX (T1.ItmsGrpNam) as GroupName,
I1.DocNum as docnum,I1.doctype as doctype , D0.CardCode as cardcode ,
MAX ( D0.CardName ) as Name ,
D1.ItemCode as 'itmcode' , D1.ocrcode as Branch ,
E1.firstname as Owner Name ,
max ( D1.Dscription ) as Descp ,
sum ( D1.Quantity ) as Quantity ,
Sum ( D1.StockPrice ) * sum ( D1.Quantity ) as Purchase Price ,
sum ( D1.Price ) * sum ( D1.Quantity ) as Sales Price ,
(sum ( D1.Price ) * sum ( D1.Quantity )) - (Sum ( D1.StockPrice ) * sum ( D1.Quantity )) AS Actual Proft / Loss
from ODLN D0 , DLN1 D1 INNER JOIN OITM T0 ON D1.ItemCode = T0.ItemCode INNER JOIN OITB T1 ON T0.ItmsGrpCod= T1.ItmsGrpCod, OHEM E1 , OINV I1, inv1 I2
where
D0.Docentry = D1.Docentry and D1.ownercode = E1.empid and I2.TargetType=-1
and D1.TrgetEntry = I1.DocEntry and I1.doctype = 'I' and upper( D1.Dscription) not like upper('%Debit%')
And I1.TaxDate BETWEEN CASE WHEN %0 = '' THEN '01/01/1900' ELSE %0 END AND CASE WHEN %1 = '' THEN GETDATE() ELSE %1 END
Group By I1.DocNum, D0.CardCode , T0.ItmsGrpCod,D1.ItemCode,D1.ocrcode , E1.firstname ,I1.doctype
union all
SELECT '' as grpcode ,
'no' as GroupName,
I1.DocNum as docnum,I1.doctype as doctype , I1.CardCode as cardcode ,
MAX ( I1.CardName ) as Name ,
' ' as itmcode , I2.ocrcode as Branch ,
E1.firstname as Owner Name ,
max ( I2.Dscription ) as Descp ,
sum ( I2.Quantity ) as Quantity ,
' 0' as Purchase Price ,
sum ( I2.linetotal) as Sales Price ,
sum ( I2.linetotal) AS Actual Proft / Loss
from OHEM E1 , OINV I1 ,inv1 I2
where
I1.DocEntry = I2.DocEntry and I2.ownercode = E1.empid and upper( I2.Dscription) not like upper('%Debit%')
and I1.doctype = 'S' And I2.TargetType=-1
And I1.TaxDate BETWEEN CASE WHEN %0 = '' THEN '01/01/1900' ELSE %0 END AND CASE WHEN %1 = '' THEN GETDATE() ELSE %1 END
Group By I1.DocNum, I1.CardCode , I2.ocrcode , E1.firstname,I1.doctype
This will not include Invoice whose Credit Memo is raised.
Regards,
Rahul
Similar Messages
-
hi all,
i have 2 udf field of type 'Time', StartTime and EndTime in order to catch the info of some process time.
again 2 fields of date in order to catch the range of days for the process goes.
like the following
Startdate | Enddate | Starttime | Endtime
15/04/09--| 16/04/09| 9:30- | ---14:00
Now i need a query to calculate the time differences in hrs. like the process runs thro 4 n half hrs a day and totally as per the table value the total run process time is 9 hrs.
How to bring out in query any one plz help...
Thank you so much,Hi Yatsea, sorry tis time too its not reteiving correct answer, the values i gave over here is jus for example. but in real there may be many different values. So will be useful in case of providing the query taking in the field names plz.
i hav a work around working on . will write here, plz guide me to correct the query to get me correct answer.
in order to find the specific hrs between start and end time for 2 days,
1. can find first total days within start and end date (EndDate-StartDate) + 1 = 2
2. 2nd find the hrs between start and end time (EndTime-StartTime) = 4.30 hrs
3. after tht should multply the 2 values 2 * 4.30 = 8.60 which should round as 9 hrs
Select (datediff(day,enddate,startdate)+1) * (endtime-starttime)
will it help..? its not giving correct answer. may gone wrong wit time format. but this concept will give correct anawer i hope...
PLz...help me getting solution.
Edited by: New User on Apr 16, 2009 3:52 PM -
what will be the peoplesoft query to calculate voluntary termination count and involuntary termination count? I am working on OBIA HR analytics workforce deployment reports and need to validate the reports. I also want to know the tables involved
Hi Andrew,
Part A:
I've done some restating of the question, and distributed the calculations among several fields, not all of which need to be included on the visible layout. Other than formatting the Date fields and moving the 'Completed Date' field and its label, I've left this in the default "Layout 1" produced by AppleWorks.
Field List:
Priority: Popup menu with six items: 00, J, D, 1, 2, 3 Defaults to 00
TL (time limit in months): Calculation: CHOOSE('Priority',0,1,3,4,6,12)
Received: Date. Option: Automatically insert today's date (ie. Date Record created) (may be edited)
Target Date: Calculation:
DATE(YEAR('Received')+INT(MONTH('Received')+'TL')/12,MOD(MONTH('Received')+'TL', 12),DAY('Received'))
Remaining (Days): Calculation: INT('Target Date'+1-NOW()) (see revision below)
Completed: Checkbox. Set default value to Unchecked.
Completed Date: Date: Entered manually
OnTarget: Calculation: IF('Completed',IF('Completed Date'<'Target Date',"On Target","Over"),IF(INT(NOW())>'Target Date',"Over","On Target"))
The On Target field shows the current status of the case while still open, and the state on the closing date when it was closed.
Having done that, I was unhappy with the Remaining field continuing to calculate an ever larger negative number after the case had been closed. Hence this revision below:
Remaining: Calculation: IF('Completed','Target Date'-'Completed Date',INT('Target Date'+1-NOW()))
Shows the number of days remaining while the case is open, the days remaining at completion if the case has been marked Completed and the completion date entered.
Rsults (and some further formatting of the Layout) below.
Part B:
You will need Subsummary parts when sorted on Completed and on On Target. Fields can appear on a Layout only once, so each subsummary part will need a separate Summary type field for each field to be summarized.
Regards,
Barry -
Need the query to calculate the time taken to excute it.
hi all,
i need the query to calculate the time taken to excute it.
for ex:
select * from emp;
how much time it will take to give o/p
Thanks in advance
satyaJust to add to what was said - the execution can each time be DIFFERENT as the factors that governs performance are NOT CONSTANT.
If Oracle has no idea how long the query is going to take before executing it, then how can you and your code know?
Oracle's CBO estimates the cost (expense) of the query. This is an indication of how expensive a query is - and the more expensive the query, the more resources need to be used, the longer the query will take. The less expensive the query, the fewer resources it need, the faster it will take.
And that is it. How fast or how slow? Oracle does not know. How much faster a query with a cost of 10,000 versus a query with a cost of 1? Oracle does not know.
Why? Because the platform is not constant. Just what data is at this exact moment in the db buffer cache? Just how much CPU capacity is available for the new few seconds? Just what will the sustained throughput be of the I/O subsystem and channels for the next minute? Just how many memory pages need to be swapped between cache and memory? Etc. etc.
All these factors change every single second. So forget about attempting to accurately calculate up-front the time it will take for a query. IT IS NOT POSSIBLE. -
SQL Query to Calculate Total PO Amount
Hi,
I'm trying to create a Purchase Order view that includes Total Po Amount. Has anyone done this before and can provide me with the SQL? Or advice on how to write the query to calculate the po_line amounts for each po number?
I've looked in the POXPOEPO.fmb form for the calculation(code) and looked at several APPS views(ie. PO_Headers_Inq_V) without any success.
Any help would be appreciated.
Thanks
TonyTony, I think this will help you:
select sum(pl.unit_price * pl.quantity)
from po_lines_all pl
, po_headers_all ph
where ph.segment1 = 1004257 -- po_number
and ph.po_header_id = pl.po_header_id
Regards,
Ricardo Cabral -
Calculate profit at row level in Discoverer Plus
HI,
I need to calculate profit at row level in Discoverer Plus as follows.
There are columns
1) Account Name- Contains Expense and revenue account names
2) Account type- Contains Identifier for account (E or R)
3) Amount --- Contains amount
4) Period Name -- Contains Numeric Amount.
Cross Tabular Report Look like as follows
Period Name Feb-2009 Mar-2009
Account Name
Total Revenue 100 90
Total Labor Cost 30 30
Total G&A Cost 20 50
Profit ??? ??
Need to show PROFIT =Total Revenue- (Total Labor Cost- Total G&A Cost)
at bottom for each period.
I am unable to use calculations because it appears column wise…
Would you please suggest solution for this?
Thanks,
Mahesh.Hi
Try dragging the data point headings off the top axis and place them to the right of the Account Name. They will all drag together so just moving one will move them all.
If your profit is already calculated and is a data point as you have commented then it too will come over to the left. For displaying it under the other items, a really cool feature about having data points on the left is that you can drag their heading and place it anywhere you want. I will be including this trick in my free March ask Michael webinar. (By the way, if anyone reading this thread you can sign up for my free webinar by clicking here: http://ascbi.com/question.htm)
You should now be able to display your calculated profit as a row underneath the other items. I tried this on my own system and it worked just fine.
Best wishes
Michael -
SQL Query to calculate on-time dispatch with a calendar table
Hi Guys,
I have a query (view) to calculate orders' fulfillment leadtimes.
The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name
isBusinessDay but I don't know how to best use this table to calculate the On-Time metric. I have been looking everywhere but so far I have been unable to solve my problem.
Please find below the current calculation for the On-Time Column:
SELECT
Week#
, ClntGroup
, CORD_DocumentCode
, DESP_DocumentCode
, Cord_Lines --#lines ordered
, CORD_Qty --total units orderd
, DESP_Lines --#lines dispatched
, DESP_Qty --total units dispatched
, Status
, d_status
, OpenDate --order open date
, DateDue
, DESP_PostedDate --order dispatched date
, DocType
, [Lead times1]
, [Lead times2]
, InFxO
, OnTime
, InFxO + OnTime AS InFullAndOneTime
, SLADue
FROM (
SELECT
DATEPART(WEEK, d.DateOpn) AS Week#
, Clients.CustCateg
, Clients.ClntGroup
, d.DocumentCode AS CORD_DocumentCode
, CDSPDocs.DocumentCode AS DESP_DocumentCode
, COUNT(CORDLines.Qnty) AS Cord_Lines
, SUM(CORDLines.Qnty) AS CORD_Qty
, COUNT(CDSPLines.Qnty) AS DESP_Lines
, SUM(CDSPLines.Qnty) AS DESP_Qty
, CDSPLines.Status
, d.Status AS d_status
, d.OpenDate
, d.DateDue
, CDSPDocs.PostDate AS DESP_PostedDate
, d.DocType
, DATEDIFF(DAY, d.OpenDate, d.DateDue) AS [Lead times1]
, DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) AS [Lead times2]
, CASE WHEN SUM(CORDLines.Qnty) = SUM(CDSPLines.Qnty) THEN 1 ELSE 0 END AS InFxO --in-full
--On-Time by order according to Despatch SLAs
, CASE
WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales', 'Mail Order')
AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2 ) <= 2)
THEN 1
WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - USA')
AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2) <= 14)
THEN 1
WHEN Clients.ClntGroup = 'Export Market' OR Clients.CustCateg = 'UK Transfer'
AND d.DateDue >= CDSPDocs.PostDate
THEN 1
ELSE 0
END AS OnTime
--SLA Due (as a control)
, CASE
WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales','Mail Order') AND CDSPDocs.PostDate is Null
THEN DATEADD(DAY, 2 , d.OpenDate)
WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - UK', 'Export Market - USA') OR (Clients.CustCateg = 'UK Transfer')
AND CDSPDocs.PostDate IS NULL
THEN DATEADD (DAY, 14 , d.OpenDate)
ELSE CDSPDocs.PostDate
END AS SLADue
FROM dbo.Documents AS d
INNER JOIN dbo.Clients
ON d.ObjectID = dbo.Clients.ClntID
AND Clients.ClientName NOT in ('Samples - Free / Give-aways')
LEFT OUTER JOIN dbo.DocumentsLines AS CORDLines
ON d.DocID = CORDLines.DocID
AND CORDLines.TrnType = 'L'
LEFT OUTER JOIN dbo.DocumentsLines AS CDSPLines
ON CORDLines.TranID = CDSPLines.SourceID
AND CDSPLines.TrnType = 'L'
AND (CDSPLines.Status = 'Posted' OR CDSPLines.Status = 'Closed')
LEFT OUTER JOIN dbo.Documents AS CDSPDocs
ON CDSPLines.DocID = CDSPDocs.DocID
LEFT OUTER JOIN DimDate
ON dimdate.[Date] = d.OpenDate
WHERE
d.DocType IN ('CASW', 'CORD', 'MORD')
AND CORDLines.LneType NOT IN ('Fght', 'MANF', 'Stor','PACK', 'EXPS')
AND CORDLines.LneType IS NOT NULL
AND d.DateDue <= CONVERT(date, GETDATE(), 101)
GROUP BY
d.DateOpn
,d.DocumentCode
,Clients.CustCateg
,CDSPDocs.DocumentCode
,d.Status
,d.DocType
,d.OpenDate
,d.DateReq
,CDSPDocs.PostDate
,CDSPLines.Status
,Clients.ClntGroup
,d.DocumentName
,d.DateDue
,d.DateOpn
) AS derived_table
Please find below the DimDate table
FullDateNZ HolidayNZ IsHolidayNZ IsBusinessDay
24/12/2014 NULL 0 1
25/12/2014 Christmas Day 1 0
26/12/2014 Boxing Day 1 0
27/12/2014 NULL 0 0
28/12/2014 NULL 0 0
29/12/2014 NULL 0 1
30/12/2014 NULL 0 1
31/12/2014 NULL 0 1
1/01/2015 New Year's Day 1 0
2/01/2015 Day after New Year's 1 0
3/01/2015 NULL 0 0
4/01/2015 NULL 0 0
5/01/2015 NULL 0 1
6/01/2015 NULL 0 1
This is what I get from the query:
Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
52 Web Sales 123456 24/12/2014 29/12/2014 0
52 Web Sales 123457 24/12/2014 30/12/2014 0
52 Web Sales 123458 24/12/2014 29/12/2014 0
52 Local Market 123459 24/12/2014 29/12/2014 0
1 Web Sale 123460 31/12/2014 5/01/2015 0
1 Local Market 123461 31/12/2014 6/01/2015 0
As the difference between the dispatched and open date is 2 business days or less, the result I expect is this:
Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
52 Web Sales 123456 24/12/2014 29/12/2014 1
52 Web Sales 123457 24/12/2014 30/12/2014 1
52 Web Sales 123458 24/12/2014 29/12/2014 1
52 Local Market 123459 24/12/2014 29/12/2014 1
1 Web Sale 123460 31/12/2014 5/01/2015 1
1 Local Market 123461 31/12/2014 6/01/2015 1
I am using SQL Server 2012
Thanks
Eric>> The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name “isBusinessDay” but I don't know how to best use this table to calculate the On-Time metric. <<
The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday.
CREATE TABLE Calendar
(cal__date date NOT NULL PRIMARY KEY,
julian_business_nbr INTEGER NOT NULL,
INSERT INTO Calendar
VALUES ('2007-04-05', 42),
('2007-04-06', 43), -- good Friday
('2007-04-07', 43),
('2007-04-08', 43), -- Easter Sunday
('2007-04-09', 44),
('2007-04-10', 45); --Tuesday
To compute the business days from Thursday of this week to next
Tuesdays:
SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
FROM Calendar AS C1, Calendar AS C2
WHERE C1.cal__date = '2007-04-05',
AND C2.cal__date = '2007-04-10';
We do not use flags in SQL; that was assembly language. I see from your code that you are still in a 1960's mindset. You used camelCase for a column name! It makes the eyes jump and screws up maintaining code; read the literature.
The “#” is illegal in ANSI/ISO Standard SQL and most other ISO Standards. You are writing 1970's Sybase dialect SQL! The rest of the code is a mess.
The one column per line, flush left and leading comma layout tells me you used punch cards when you were learning programming; me too! We did wrote that crap because a card had only 80 columns and uppercase only IBM 027 character sets. STOP IT, it make you
look stupid in 2015.
You should follow ISO-11179 rules for naming data elements. You failed. You believe that “status” is a precise, context independent data element name! NO!
You should follow ISO-8601 rules for displaying temporal data. But you used a horrible local dialect. WHY?? The “yyyy-mm-dd” is the only format in ANSI/ISO Standard SQL. And it is one of the most common standards embedded in ISO standards. Then you used crap
like “6/01/2015” which is varying length and ambiguous that might be “2015-06-01” or “2015-01-06” as well as not using dashes.
We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL.
And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
>> Please find below the current calculation for the On-Time Column: <<
“No matter how far you have gone down the wrong road, turn around”
-- Turkish proverb
Can you throw out this mess and start over? If you do not, then be ready to have performance got to hell? You will have no maintainable code that has to be kludged like you are doing now? In a good schema an OUTER JOIN is rare, but you have more of them in
ONE statement than I have seen in entire major corporation databases.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
TSQL query to calculate Count / Sum grouping by date on a Pivot Table
Hi All
I need help to group the pivot table output to group by dates and sum/count the values. I have a table like shown below.
Date
Student
Subject
Hunt
Marks
18/02/2014
Sam
Maths
1
20
18/02/2014
Sam
Maths
1
10
18/02/2014
Sam
Maths
2
30
18/02/2014
Luke
Science
1
50
17/02/2014
Sam
Maths
2
50
17/02/2014
Luke
Science
2
60
16/02/2014
Luke
Science
2
20
16/02/2014
Luke
Science
3
20
I want to Group by dates and move the Hunt to columns calculating their counts and sum their marks too. Like given below.
I wrote a pivot query like below but If i group it with dates and calculate the total marks it throws aggregate errors.
Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
Go
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
Go
select * from Student_Log
select [DATE] , [Student], [Subject] ,[1],[2],[3],[4],Total =([1]+[2]+[3]+[4])
from
( select [Date], [Student], [Subject],[Hunt],[Marks] from Student_Log
)x
pivot
count ( [Hunt]) for [Hunt]
in ([1],[2],[3],[4])
)p
order by [Date] desc
I have done this far only. More than this I need to enhance it with the Percentage of Hunts for each Student.
ie like below table.
On 18th Sam in Maths he had 2 rows on 1st hunt and 1 row on 2nd hunt. So On the Pivot table is it possible to represent it on percentage using the Total Attempts column.
Thanks a lot in advance.
Its runnung in SQL 2000 Server.Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
Go
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
Go
select * from Student_Log
;with mycte as
Select [Date], [Student], [Subject] ,
Count(CASE WHEN [Hunt]=1 Then Hunt End) as Hunt1,
Count(CASE WHEN [Hunt]=2 Then Hunt End) as Hunt2,
Count(CASE WHEN [Hunt]=3 Then Hunt End) as Hunt3,
Count(CASE WHEN [Hunt]=4 Then Hunt End) as Hunt4,
Count(CASE WHEN [Hunt]=1 Then Hunt End)
+Count(CASE WHEN [Hunt]=2 Then Hunt End)
+Count(CASE WHEN [Hunt]=3 Then Hunt End)+
+Count(CASE WHEN [Hunt]=4 Then Hunt End) as Total,
ISNULL(SUM(CASE WHEN [Hunt]=1 Then Marks End),0) as Mark1,
ISNULL(SUM(CASE WHEN [Hunt]=2 Then Marks End),0) as Mark2,
ISNULL(SUM(CASE WHEN [Hunt]=3 Then Marks End),0) as Mark3,
ISNULL(SUM(CASE WHEN [Hunt]=4 Then Marks End),0) as Mark4
from Student_Log
Group By [Date], [Student], [Subject]
Select [Date], [Student], [Subject]
, Cast(Hunt1*1./Total*100 as int) as [1]
, Cast(Hunt2*1./Total*100 as int) as [2]
,Cast(Hunt3*1./Total*100 as int) as [3]
,Cast(Hunt4*1./Total*100 as int) as [4]
,Total,Marks=( Mark1+Mark2+Mark3+Mark4)
from mycte
order by [Date] DESC, Student desc
drop table Student_Log -
Query to calculate time frames
hello,
id like to write a query that will calculate time frames ;
my source table looks like this:
company category date
ORACLE A 1/01/2012
ORACLE A 2/01/2012
ORACLE B 3/01/2012
ORACLE C 4/01/2012
IBM A 1/01/2012
IBM A 2/01/2012
IBM A 3/01/2012
IBM A 4/01/2012my desired result:
company category from to
ORACLE A 1/01/2012 2/01/2012
ORACLE B 3/01/2012 3/01/2012
ORACLE C 4/01/2012 31/12/2999
IBM A 1/01/2012 31/12/2999can you please guide me with use of which functions i can achieve that?
id appreciate any tips
thank you
rgds
Edited by: UserMB on Jan 11, 2012 5:14 PMOne way...
ME_XE?with t as
2 (
3 select 'ORACLE' col1, 'A' col2, to_date('1/01/2012', 'dd/mm/yyyy') col3
4 from dual
5 union all
6 select 'ORACLE', 'A', to_date('2/01/2012', 'dd/mm/yyyy')
7 from dual
8 union all
9 select 'ORACLE', 'B', to_date('3/01/2012', 'dd/mm/yyyy')
10 from dual
11 union all
12 select 'ORACLE', 'C', to_date('4/01/2012', 'dd/mm/yyyy')
13 from dual
14 union all
15 select 'IBM', 'A', to_date('1/01/2012', 'dd/mm/yyyy')
16 from dual
17 union all
18 select 'IBM', 'A', to_date('2/01/2012', 'dd/mm/yyyy')
19 from dual
20 union all
21 select 'IBM', 'A', to_date('3/01/2012', 'dd/mm/yyyy')
22 from dual
23 union all
24 select 'IBM', 'A', to_date('4/01/2012', 'dd/mm/yyyy') from dual
25 )
26 select
27 col1, col2, min(col3), case when max(col3) = max_company_date then to_date('31/12/2999','dd/mm/yyyy') else max(col3) end
28 from
29 (
30 select col1, col2, col3, max(col3) over (partition by col1) as max_company_date
31 from t
32 )
33 group by col1, col2, max_company_date;
COL1 COL MIN(COL3) CASEWHENMAX(COL3)=MAX_COMP
ORACLE B 03-JAN-2012 12 00:00 03-JAN-2012 12 00:00
ORACLE A 01-JAN-2012 12 00:00 02-JAN-2012 12 00:00
ORACLE C 04-JAN-2012 12 00:00 31-DEC-2999 12 00:00
IBM A 01-JAN-2012 12 00:00 31-DEC-2999 12 00:00
4 rows selected.
Elapsed: 00:00:00.01
ME_XE? -
Query Designer: calculate relative revenue
Hi,
I would like to calculate the relative revenue (= revenue / revenue of the biggest market participant) in the BEx Query Designer. I have a key figure "revenue" and my market participant as characteristic.
I first tried to create a formula like "revenue / max(revenue)" but this doesn't work that way in Query Designer. I now tried to solve this with a calculated keyfigure but don't come to a solution.
How can I do a calculation like this in Query Designer?
Thanks!Create a 'Replacement Path' variable having reference to 'Market Participant' characteristic. Use this variable in your formula and use the Max. function on 'Market Participant' variable.
Hope this helps. -
Hi,
I'm trying to build the dax query to determine the distinct count for a column returned by the application of a Filter function.
evaluate(
row("counter",
countrows(
filter(order_summary,
year(order_summary[change_date]) = 2013) )
I need to count the distinct values for an id returned by the Filter function.
Any helps, please? ThanksHi pscorca,
According to your description, you want to calculate the distinct values for records where change_date is 2013. Right?
In this scenario, we can use the DISTINCT() function within COUNTROWS(). Please try the expression below:
=calculate(
countrows(distinct(order_summary[column])),
Filter('order_summary', year(order_summary[change_date])=2013)
Reference:
Distinct Count Measure in PowerPivot using DAX
Related Distinct Count
Best Regards,
Simon Hou
TechNet Community Support -
How does optimiser calculate profit for profit maximisation
Hi Experts,
I have a basic question-
when we work on 'profit maximisation' how does the system calculate profits. As I understand the calculation is revenue- total cost. costs is what we define in the system. But how is the revenue calculated?
What it the logic where profit maximisation is selected over cost minimisation?
Regards
ManotoshHi Manotosh,
For answering the first part of your question, I am just copy pasting the F1 help for the field from Optimizer profile:
"Profit Maximization
Use
It is the optimizer's objective, when using either of the two possible options: cost minimization or profit maximization, to determine the most cost-effective solution based on the costs defined in Cost Maintenance.
If you choose Profit Maximization, the system interprets the Penalty for ND field (penalty costs for non-delivery) in the product master (tab page SNP 1) as lost profits. In this instance, the total profit achieved by a plan is calculated according to the following formula: Total of all delivered location products, multiplied by the penalty costs for non-delivery that have been defined for these location products, minus all the costs defined in the optimizer cost profile (such as production costs, storage costs and transportation costs). The total profit is displayed, when you run the optimizer in interactive planning within Supply Network Planning (on the Solutions tab page)."
For second part, someone who has worked on solution design in a project where Optimizer was used might possibly give a good answer. I am not very sure, though I can make a guess as follows:
You would go for cost minimization in a scenario where your requirement would be to minimize overall cost, even if it leads to non-fulfillment of requirement. Could be a scenario where e.g. lost sales are not very critical for you. e.g. products like generic bulbs, etc. On the other hand, where you want that the requirements fulfillment should also be one of the key objectives, you would go for profit maximization. This could be a case where brand plays a major role e.g. TV, costly gizmos, etc.
Hope someone else will correct me, or add to this.
Thanks - Pawan -
FMS Query for default Profit Center in SO
Dear Experts,
Can anybody help me by providing FMS query for getting default Profit Center based on the default Warehouse in the user default settings.
Regards
SriniHi Rahul,
I created each Branch as a profit Centre and the filed name is OPRC.PrcCode . If the user at a particular branch logged in SAP by using his ID and when he is adding a SO the profit centres list should appear in Profit centre filed.
And is there any provision to set the profit centre (OPRC.Code) as default for the user at a branch by taking document no.series or location ID or User ID as consideration in the FMS query.
Thanks
Srinivas -
Informix / SQL Query to calculate Service Level Met %
Hi,
We have a client running UCCX 7.0 and we are upgrading it to 8.5.
They have a custom .net application that display different stats on IP Phone. I have converted all of them except i am having problem calculating Service Level Met %
Existing SQL query converts boolean into Float but Informix gives error that boolean can't be converted to float or integer.
here is part of existing query (SQl Server) to calculate service level met %
ROUND((SUM(CAST(ssl.metServiceLevel AS FLOAT))/COUNT(CAST(ssl.metServiceLevel AS FLOAT))) * 100,2) AS serviceLevelMet
I will greatly appreciate if anyone can help converting this query into Informix query format.
Thank youHi Sonain
Try this, it won't display a service level until you have received at least one call on the CSQ.
SELECT csqsum.CSQName,loggedInAgents,talkingAgents,availableAgents,workingAgents,reservedAgents,servicelevel
FROM RtCSQsSummary csqSum left outer join
(SELECT csqname, ROUND(sum(100 * (MetSL)/ (case when (MetSL + NotSL = 0) then 1 else (MetSL + NotSL) end)) ) as servicelevel
FROM(
SELECT
trim( csqname) csqname
,sum( case cqd.metServiceLevel when 't' then 1 else 0 end) MetSL
,sum( case cqd.metServiceLevel when 't' then 0 else 1 end) NotSL
FROM ContactServiceQueue csq
inner join contactqueuedetail cqd on cqd.targetID = csq.recordID
inner join contactroutingdetail crd on crd.sessionID = cqd.sessionID
inner join contactcalldetail ccd on crd.sessionID = ccd.sessionID
WHERE Date(current) - Date(crd.StartDateTime ) = 0
GROUP BY csqname
)z
GROUP BY z.csqname
)y
ON y.CSQName = csqsum.CSQName
Please rate helpfull posts.
Graham -
Query Designer: Calculate a % based on two other totals
Hi Gurus,
Here is the scenario of my query:
A B C D E
2 3 6 4 150%
1 2 2 4 50%
2 2 4 8 50%
1 1 1 10 10%
6 8 13 26 50%
Column C is calulated by AB and I am able to get the total 13 instead of 48 (68) by using the "Total" calculation function.
The problem is about the Total of Column E. It is a % based on columns C versus D. There's no problem for individual results, but for the total I cannot get the 50% because my query calculates the total result comparing 48 (6*8) Vs 26.
If I also use the Total function for the E Column, what it shows is an addition of all the individual results, so 260%.
I can't find the way to get the Total 50% that takes the "Total" function of Column C and Column D.
Please, any idea so solve this scenario?
Many thanks!!
Regards,
JordiHi,
The "Calculate Result As" is a Display option. That value is not considered in the calculations, only for display.
You may try "Exception Aggregation" , 'Total' for Column C with Ref Characteristic being the Char at the lowest level of which you see the data and try.
For eg: you can to calculate A x B for Materials, but at all levels higher than material you want A1 x B1 + A2 x B2 + .....
Then you create CKF/Formula C = A x B with Exp Aggregation, Total, Ref Char = Material.
Maybe you are looking for
-
Oracle 10G Browse object feature
Hi there I am new to oracle, i have used browse Object in oracle 10g as an easy way to create my table instead of scripting. however, i don't know how to assign two FK to the same table (employee table that contains Managers). can anyone tell me in s
-
Use of Class Vs Interface for defining application constants
I want to use some constants through out the application. For that I found two ways to do that as given below 1. We can define constants in a class as public class ConstantClass { public static final String applConstant = "Some Constant"; and use it
-
Run Webdypro Java application by default
Hi , Is that possible to run a Webdynpro Java application by default when User logs into Portal? Actual requirement is that we need to assign Users with different ume groups once User login to portal depending on some User attributes. I am thinking a
-
"Open With" CS3 not working for JPEG file
Operating system is XP. I am trying to get CS3 to automatically open all JPEG files when I double click on them in windows explorer. I open windows explorer, right click on the image that I want to open, then click "open with" .... ...at this point C
-
hello, i need to get access to these archives here: http://rzblx10.uni-regensburg.de/dbinfo - 28#ZEITUNG for that i need a winframe-client. i got here some help (in german): http://www.ulb.uni-bonn.de/ebibliothek/ - /index.htm i tried the wincenter.s