If I use the InvoiceDate as a table criteria, it takes 10x longer to run the BAQ. If I put it as a criteria on the dashboard, it doesn’t return anything.
SQL from BAQ:
select
[InvcHead].[InvoiceDate] as [InvcHead_InvoiceDate],
[InvcHead].[InvoiceNum] as [InvcHead_InvoiceNum],
[OrderHed].[UserChar1] as [OrderHed_UserChar1],
[OrderHed].[UserChar01] as [OrderHed_UserChar01],
[SalesRep].[Name] as [SalesRep_Name],
[SalesRep].[CSGSlsDivision_c] as [SalesRep_CSGSlsDivision_c],
[InvcDtl].[OrderNum] as [InvcDtl_OrderNum],
[InvcDtl].[OrderLine] as [InvcDtl_OrderLine],
[Customer].[CustID] as [Customer_CustID],
[Customer].[Name] as [Customer_Name],
[OrderHed].[ShipToNum] as [OrderHed_ShipToNum],
[ShipTo].[Name] as [ShipTo_Name],
[ShipTo].[Address1] as [ShipTo_Address1],
[InvcDtl].[PartNum] as [InvcDtl_PartNum],
(IsNull(Part.PartDescription, InvcDtl.LineDesc)) as [Calculated_PartDesc],
[InvcDtl].[SellingShipQty] as [InvcDtl_SellingShipQty],
[InvcDtl].[InvoiceLine] as [InvcDtl_InvoiceLine],
(InvcDtl.DocUnitPrice - case when InvcDtl.SellingShipQty = 0 then 0 else(InvcDtl.DocDiscount / InvcDtl.SellingShipQty) end) as [Calculated_UnitPrice],
(InvcDtl.DocExtPrice - InvcDtl.DocDiscount) as [Calculated_ExtPrice],
(IsNull((InvcDtlCredit.MtlUnitCost + InvcDtlCredit.LbrUnitCost + InvcDtlCredit.BurUnitCost + InvcDtlCredit.SubUnitCost + InvcDtlCredit.MtlBurUnitCost) * -1
,
case when OrderDtl.Company is null then 0 else InvcDtl.MtlUnitCost + InvcDtl.LbrUnitCost + InvcDtl.BurUnitCost + InvcDtl.SubUnitCost + InvcDtl.MtlBurUnitCost end)) as [Calculated_UnitCost],
(ExtPrice - ExtCost) as [Calculated_GrossProfit],
(case when ExtPrice = 0 then 0 else
1 - (ExtCost / ExtPrice)
end) as [Calculated_GrossMargin],
(case when InvcHead.Posted = 1 then 'Yes' else 'No' end) as [Calculated_cmbPosted],
(UnitCost * abs( InvcDtl.SellingShipQty )) as [Calculated_ExtCost],
(IsNull(RefCategory.Description, case when Part.Company is null then 'Buy To Order' else '' end)) as [Calculated_Reference],
[InvcHead].[CreditMemo] as [InvcHead_CreditMemo],
[OrderHed].[Division_c] as [OrderHed_Division_c],
[COASegValues].[SegmentAbbrev] as [COASegValues_SegmentAbbrev],
[OrderHed].[PONum] as [OrderHed_PONum],
[OrderHed].[NippleUpDate_c] as [OrderHed_NippleUpDate_c],
[OrderHed].[NippleDownDate_c] as [OrderHed_NippleDownDate_c],
[Part].[ProdCode] as [Part_ProdCode],
[InvcHead].[ApplyDate] as [InvcHead_ApplyDate],
[OrderHed].[TicketNumber_c] as [OrderHed_TicketNumber_c],
[InvcHead].[DueDate] as [InvcHead_DueDate],
[InvcHead].[OpenInvoice] as [InvcHead_OpenInvoice],
[InvcHead].[Plant] as [InvcHead_Plant],
(case when InvcHead.OpenInvoice = 1 then
DATEDIFF(day,InvcHead.DueDate,GetDate())
else 0 end) as [Calculated_DaysLate],
(case
when DaysLate <=0 then ''
when DaysLate < 30 then '0-29'
when DaysLate < 60 then '30-59'
when DaysLate < 90 then '60-89'
when DaysLate < 120 then '90-119'
else '120+'
end) as [Calculated_DaysLateGroup],
(InvcHead.InvoiceDate) as [Calculated_InvoiceDate]
from Erp.InvcHead as InvcHead
inner join Erp.Customer as Customer on
InvcHead.Company = Customer.Company
and InvcHead.CustNum = Customer.CustNum
inner join Erp.InvcDtl as InvcDtl on
InvcHead.Company = InvcDtl.Company
and InvcHead.InvoiceNum = InvcDtl.InvoiceNum
and ( InvcDtl.Company = @CompanyID )
left outer join Erp.OrderDtl as OrderDtl on
InvcDtl.Company = OrderDtl.Company
and InvcDtl.OrderNum = OrderDtl.OrderNum
and InvcDtl.OrderLine = OrderDtl.OrderLine
and ( OrderDtl.Company = @CompanyID )
left outer join Erp.OrderHed as OrderHed on
OrderDtl.Company = OrderHed.Company
and OrderDtl.OrderNum = OrderHed.OrderNum
and ( OrderHed.Company = @CompanyID )
left outer join Erp.SalesRep as SalesRep on
OrderHed.UserChar01 = SalesRep.SalesRepCode
OrderHed.Company = SalesRep.Company
left outer join Erp.COASegValues as COASegValues on
OrderHed.Company = COASegValues.Company
and OrderHed.Division_c = COASegValues.SegmentCode
and ( COASegValues.Company = @CompanyID and COASegValues.SegmentNbr = 2 and COASegValues.COACode = 'POCOA' )
inner join Erp.ShipTo as ShipTo on
InvcDtl.Company = ShipTo.Company
and InvcDtl.ShipToCustNum = ShipTo.CustNum
and InvcDtl.ShipToNum = ShipTo.ShipToNum
and ( ShipTo.Company = @CompanyID )
left outer join Erp.Part as Part on
InvcDtl.Company = Part.Company
and InvcDtl.PartNum = Part.PartNum
and ( Part.Company = @CompanyID )
left outer join Erp.RefCategory as RefCategory on
Part.Company = RefCategory.Company
and Part.RefCategory = RefCategory.RefCategory
and ( RefCategory.Company = @CompanyID )
left outer join Erp.InvcDtl as InvcDtlCredit on
InvcDtl.Company = InvcDtlCredit.Company
and InvcDtl.InvoiceRef = InvcDtlCredit.InvoiceNum
and InvcDtl.InvoiceLineRef = InvcDtlCredit.InvoiceLine
and ( InvcDtlCredit.Company = @CompanyID )
where (InvcHead.Company = @CompanyID and InvcHead.InvoiceDate >= '1/1/2020')