on 01-12-2015 4:11 PM
Hello Experts,
I'm looking for a query that will report the average days late for all of our vendors within a particular date range. Would any of you have a query that will report these averages by vendor or know of a report already in SBO 9.0 that will perform this evaluation?
Hi,
There is no standard report for late delivery. We have to create query to get average delays.
Thanks & Regards,
Nagarajan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nagarajan,
I'm working with the query below but don't understand why it reports many more lines than i have line items in the purchase order. Would you be able to explain what is going on?
Also, is there a way to write a formula into the query that will average the days late for the vendors?
SELECT T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[CardName], T0.[NumAtCard], T3.[DocDate], DateDiff (dd, T0.DocDueDate,T3.DocDate) 'Delay' FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry INNER JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
Hi,
Try this query without Avg delay.
SELECT T0.[DocNum], T0.[DocDate] , T0.[DocDueDate] , T0.[CardName] , T0.[NumAtCard] , T3.[DocDate] , cast(DateDiff (dd, T0.DocDueDate,T3.DocDate) as Numeric) as Delay
FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry and T2.[BaseLine] = T1.[LineNum] INNER JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
group by T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[CardName], T0.[NumAtCard], T3.[DocDate]
Try:
SELECT T0.[DocNum], T0.[DocDate] , T0.[DocDueDate] , T0.[CardName] , T0.[NumAtCard] , T3.[DocDate] , cast(DateDiff (dd, T0.DocDueDate,T3.DocDate) as Numeric) as Delay
FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry and T2.[BaseLine] = T1.[LineNum] left JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
group by T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[CardName], T0.[NumAtCard], T3.[DocDate]
Hi,
Try:
SELECT T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[CardName], T0.[NumAtCard], IsNull(T3.[DocDate],'') 'GRPO Date', DateDiff (dd, T0.DocDueDate,T3.DocDate) 'Delay'
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry AND T1.LineNum=T2.BaseLine
LEFT JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
What do you get? Show a screenshot.
Thanks,
Gordon
Gordon, I see another issue. At times when we place a PO with a vendor they give different delivery dates for the various items. In those cases we put the item specific delivery dates on the line item. It appears the query you have suggested is looking at the delivery date for the PO put i also need it to look at the line item delivery date being that those dates may vary. Can this be done?
Ok Gentlemen,
I have received the Mastering SQL Queries for SBO book and have read through it. It is an excellent resource and I am most positive that I will be referring to it quite often but I still need a little guidance.
The query below is what I have ended up with thus far. I plan to export the query into excel and use the subtotal function to calculate the average days late for each vendor. The dilemma I have now is that the current query returns the 'Delay' as both early deliveries (calculation returns negative number), on time (result of ''), as well as late ones (calculated numbers are positive).
All I need are late deliveries. The 'Delay' that is > 0. What would be the best way to "exclude" the 'Delay' that is <= 0 and only return the positive calculations? Or if you look at it the other way... only return the values of 'Delay' that or > 0.
SELECT T0.[DocNum] 'PO #', T0.[DocDate] 'PO Posting Date', T1.[ShipDate] 'PO Line Item Due Date', T0.[DocDueDate] 'PO Due Date', T0.[CardName], T0.[NumAtCard], IsNull(T3.[DocDate],'') 'GRPO Date', DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry AND T1.LineNum=T2.BaseLine
LEFT JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Great. You have correct resource to learn queries in SAP B1. My suggestions, read and try to write simple queries to understand SAP B1 tables and its links.
Try this query:
SELECT T0.[DocNum] 'PO #', T0.[DocDate] 'PO Posting Date', T1.[ShipDate] 'PO Line Item Due Date', T0.[DocDueDate] 'PO Due Date', T0.[CardName], T0.[NumAtCard], IsNull(T3.[DocDate],'') 'GRPO Date', DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry AND T1.LineNum=T2.BaseLine
LEFT JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1]
group by T0.[DocNum], T0.[DocDate], T1.[ShipDate] , T0.[DocDueDate] , T0.[CardName], T0.[NumAtCard], T3.[DocDate], T1.ShipDate,T0.DocDueDate,T3.DocDate
Having DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) >0
All the best.
Thanks,
Nagarajan
Thank you Nagarajan,
Honestly I totally forgot about the Having clause but it appears to raise an issue because of the Group By clause. I see that my averages are a little off due to the fact that some items on the same PO are received on the same day and the Group By is combining them.
I added another "and" to the Where clause just to see if it would take it and it appears to be working. Do you see any issue with setting up the Where clause this way?
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1] and DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) >0
I think no problem in where clause. Try this query:
SELECT T0.[DocNum] 'PO #', T0.[DocDate] 'PO Posting Date', T1.[ShipDate] 'PO Line Item Due Date', T0.[DocDueDate] 'PO Due Date', T0.[CardName], T0.[NumAtCard], IsNull(T3.[DocDate],'') 'GRPO Date', DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry AND T1.LineNum=T2.BaseLine
LEFT JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1] and DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) >0
group by T0.[DocNum], T0.[DocDate], T1.[ShipDate] , T0.[DocDueDate] , T0.[CardName], T0.[NumAtCard], T3.[DocDate], T1.ShipDate,T0.DocDueDate,T3.DocDate
Having DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) >0
I'm trying to avoid the Group By clause. I believe it is grouping some of the data and I don't want it to.
This is what I have now and it seems to be working.
SELECT T0.[DocNum] 'PO #', T0.[DocDate] 'PO Posting Date', T1.[ShipDate] 'PO Line Item Due Date', T0.[DocDueDate] 'PO Due Date', T0.[CardName], T0.[NumAtCard], IsNull(T3.[DocDate],'') 'GRPO Date', DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
FROM OPOR T0
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PDN1 T2 ON T0.DocEntry=T2.BaseEntry AND T1.LineNum=T2.BaseLine
LEFT JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry
WHERE T0.DocDate>= [%0] and T0.DocDate<=[%1] and DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) >0
Order By T0.[CardName] ASC
I'm not sure I understand the question Nagarajan. If you are referring to the DateDiff calculation:
DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
In some cases our purchasing department will receive different delivery dates for various items on the same PO. When that occurs... they put the differing delivery dates on the related line items. So in my DateDiff calculation I needed it to look at the line item Due Date from POR1 and if it is empty use the Doc Due Date from the PO (OPOR) to calculate the difference in days from when it was received with a goods receipt (OPDN).
Not sure if that is what you where asking?
So your saying i don't need the IsNull statement?
DateDiff (dd,T1.ShipDate,T3.DocDate) 'Delay'
Will return the same result as:
DateDiff (dd, ISNULL(T1.ShipDate,T0.DocDueDate),T3.DocDate) 'Delay'
Because the system automatically looks at T0. DocDue Date if T1.ShipDate is empty?
I just want to make sure I understand why you where asking the question...
"Before close this thread, i would like to clarify that, why you have added field T0.DocDueDate is "Delay" calculation."
Any update? Did you find the book?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
104 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.