Sales by State reporting

I’m curious how I can create a query with OTS.State + the actual ShipTo.State location correctly.

The tables that are needed are, InvcHead (amounts and balances), Customer, OrderHed (OTS stuff), ShipHead, ShipDtl (??), and ShipTo.

How can I connect all of these together without getting 7,000,000 rows? It doesn’t seem like the Shipping tables connect to Order/Invc tables very nicely… Am I missing something?

Essentially what I’d like to see is the Sales totals for each ship to state… The problem is we use OTS for some of our orders (OrderHed.OTSAddress1, etc.) and then we use the customer level ship to information (Customer.Address1, etc.), and we also use the Customer ShipTo’s as well (ShipTo.Address1, etc. - I believe). These don’t seem to play nicely together

I’m no BAQ expert but I envision:

Then build your sales off that

Answer: Dont look at the sales order.
Start with a query on the INVOICE DETAIL and link back to the Ship Header (always a 1 to 1 link)… the ship header should show the shipping address. But the invoice header may also show it.

1 Like

What I have had to do in this case is to create a calculated field to first look for the OTS checkbox first, if that is false look at the ship to num field, if that is null, then default to the sold to address.

Tim is right that sales should start with the invoice tables, but I found it best to then get back to the order header and do the calculated ship to field. You may need multiple calculation for each ship to detail field you need.

HTH

Brad

If this is for tax reporting, Epicor wrote a really cool report: Sales Tax. It reports everything by Tax Code or Tax Region. If one creates the tax entries (even for zero rates) and maintains them on the Customers/Ship-Tos/Order Rels, then this becomes a much easier report. People avoid doing it everywhere I’ve worked for some reason but once done, it’s beautiful.

Mark W.

2 Likes

Are you on 10.2? I can’t add a calculated field as a field to join unless I use subqueries…

As soon as I bring in the ShipTo table it gives me 7 million rows or something silly like that…

I looked a bit deeper and the OTS info is in the Onvoid=ce

From invoice detail table, join the Ship To table, links are by company, custnum and shipto. The link type should be all invoice detail rows

From the invoice detail table, join the customer table by company and custnum. Matching rows type.

I added the invoice header to know the invoice date, posted, etc.

In the resulting baq create a calculated field to do a case when then else statement.

Case When invdtl.OTS = TRUE then Invdtl.OTSstate

When invdtl.shiptonum > ‘’ then ShipTo.State

Else Customer.State

My syntax is not quite right here by you get the idea.

Then you can sort, group or filter in dashboards or reports by the calculated field.

FYI

Brad

True. So we need OrderHed.OTSstate plus any ShipTo.State info as well… When I bring in the ShipTo table it blows up my query. As far as I know, this is the only table that contains the actual ShipTo State from the pack. If I wanted to just display the invoice total (DocInvoiceBal or whatever the field is) and where the pack actually shipped then I get a bunch of rows (somewhere in the millions) - I’ll keep messing with it.

On the link with the ShipTo table be sure you have both the customer number and the ship to number linked.

Here’s what I have the join set to -

Also here’s my query so far - (tons of duplicate rows for each invoice/pack…) -
select
[InvcDtl].[InvoiceNum] as [InvcDtl_InvoiceNum],
[InvcDtl].[InvoiceLine] as [InvcDtl_InvoiceLine],
[ShipTo].[State] as [ShipTo_State],
[Customer].[State] as [Customer_State],
[InvcHead].[Posted] as [InvcHead_Posted],
[InvcHead].[DocInvoiceBal] as [InvcHead_DocInvoiceBal],
[InvcHead].[DocInvoiceAmt] as [InvcHead_DocInvoiceAmt],
(case
when InvcDtl.UseOTS = ‘1’ then InvcDtl.OTSState
when InvcDtl.ShipToCustNum > ‘’ then ShipTo.State
else Customer.State
end) as [Calculated_TheShipTo]
from Erp.InvcDtl as InvcDtl
left outer join Erp.ShipTo as ShipTo on
InvcDtl.Company = ShipTo.Company
And
InvcDtl.CustNum = ShipTo.CustNum
And
InvcDtl.ShipToNum = ShipTo.ShipToNum

inner join Erp.Customer as Customer on
InvcDtl.Company = Customer.Company
And
InvcDtl.CustNum = Customer.CustNum

inner join Erp.InvcHead as InvcHead on
Customer.Company = InvcHead.Company
And
Customer.CustNum = InvcHead.CustNum
and ( InvcHead.Posted = 1 )

Caleb,

This should be Invcdtl.shiptonum (not shiptocustnum)

when InvcDtl.UseOTS = ‘1’ then InvcDtl.OTSState
when InvcDtl.ShipToCustNum > ‘’ then ShipTo.State
else Customer.State
end) as [Calculated_TheShipTo]
from Erp.InvcDtl as InvcDtl
left outer join Erp.ShipTo as ShipTo on
InvcDtl.Company = ShipTo.Company
And
InvcDtl.CustNum = ShipTo.CustNum
And
InvcDtl.ShipToNum = ShipTo.ShipToNum

inner join Erp.Customer as Customer on
InvcDtl.Company = Customer.Company
And
InvcDtl.CustNum = Customer.CustNum

inner join Erp.InvcHead as InvcHead on
Customer.Company = InvcHead.Company
And
Customer.CustNum = InvcHead.CustNum
and ( InvcHead.Posted = 1 )