Ive got this BAQ that estimates the cost of a single scrapped part at any given operation. The BAQ works alright. I get a few columns to add up at the end.
It should be easy to add up the values for these 4 columns, to show a single total per row. But this is not working like I expect. Some rows dont get a total at all, and some do.
The formula for the field in question is a simple sum:
SubQuery1.Calculated_NewLaborCostTotal + SubQuery1.Calculated_MaterialTotal + SubQuery1.Calculated_SubContractTotal + SubQuery1.Calculated_BurdenCostTotal
Here is my BAQ:
select
[SubQuery1].[JobOper_JobNum] as [JobOper_JobNum],
[SubQuery1].[JobHead_PartNum] as [JobHead_PartNum],
[SubQuery1].[JobOper_AssemblySeq] as [JobOper_AssemblySeq],
[SubQuery1].[JobAsmbl_RequiredQty] as [JobAsmbl_RequiredQty],
[SubQuery1].[JobAsmbl_PartNum] as [JobAsmbl_PartNum],
[SubQuery1].[JobOper_OprSeq] as [JobOper_OprSeq],
[SubQuery1].[JobOper_OpDesc] as [JobOper_OpDesc],
[SubQuery1].[JobOper_ActProdHours] as [JobOper_ActProdHours],
[SubQuery1].[JobOper_ActSetupHours] as [JobOper_ActSetupHours],
[SubQuery1].[JobOper_SubContract] as [JobOper_SubContract],
[SubQuery1].[JobOper_ActLabCost] as [JobOper_ActLabCost],
[SubQuery1].[JobHead_ProdQty] as [JobHead_ProdQty],
[SubQuery1].[JobOper_QtyCompleted] as [JobOper_QtyCompleted],
[SubQuery1].[JobOper_RunQty] as [JobOper_RunQty],
[SubQuery1].[JobOper_QtyPer] as [JobOper_QtyPer],
[SubQuery1].[Calculated_MyQty] as [Calculated_MyQty],
[SubQuery1].[Calculated_NewLaborCostTotal] as [Calculated_NewLaborCostTotal],
[SubQuery1].[Calculated_MaterialTotal] as [Calculated_MaterialTotal],
[SubQuery1].[Calculated_SubContractTotal] as [Calculated_SubContractTotal],
[SubQuery1].[Calculated_BurdenCostTotal] as [Calculated_BurdenCostTotal],
(SubQuery1.Calculated_NewLaborCostTotal+SubQuery1.Calculated_MaterialTotal+SubQuery1.Calculated_SubContractTotal+SubQuery1.Calculated_BurdenCostTotal) as [Calculated_SinglePartTotal]
from (select distinct
[JobOper].[JobNum] as [JobOper_JobNum],
[JobHead].[PartNum] as [JobHead_PartNum],
[JobOper].[AssemblySeq] as [JobOper_AssemblySeq],
[JobAsmbl].[RequiredQty] as [JobAsmbl_RequiredQty],
[JobAsmbl].[PartNum] as [JobAsmbl_PartNum],
[JobOper].[OprSeq] as [JobOper_OprSeq],
[JobOper].[OpDesc] as [JobOper_OpDesc],
[JobOper].[ActProdHours] as [JobOper_ActProdHours],
[JobOper].[ActSetupHours] as [JobOper_ActSetupHours],
[JobOper].[SubContract] as [JobOper_SubContract],
[JobOper].[ActLabCost] as [JobOper_ActLabCost],
[JobHead].[ProdQty] as [JobHead_ProdQty],
[JobOper].[QtyCompleted] as [JobOper_QtyCompleted],
[JobOper].[RunQty] as [JobOper_RunQty],
[JobOper].[QtyPer] as [JobOper_QtyPer],
(iif(JobOper.QtyCompleted=0,0,JobOper.QtyCompleted)) as [Calculated_MyQty],
(iif(MyQty=0,0,iif(JobOper.SubContract=0, JobOper.ActLabCost/ MyQty, 0))) as [Calculated_NewLaborCostTotal],
(iif(MyQty=0,0,sum(JobMtl.TotalCost) / MyQty)) as [Calculated_MaterialTotal],
(iif(MyQty=0,0,iif(JobOper.SubContract=1, JobOper.ActLabCost/ MyQty, 0))) as [Calculated_SubContractTotal],
(iif(MyQty=0,0,JobOper.ActBurCost / MyQty)) as [Calculated_BurdenCostTotal]
from Erp.JobHead as [JobHead]
inner join Erp.JobAsmbl as [JobAsmbl] on
JobHead.Company = JobAsmbl.Company
and JobHead.JobNum = JobAsmbl.JobNum
and ( JobAsmbl.PartNum = @DetailPart )
inner join Erp.JobOper as [JobOper] on
JobAsmbl.Company = JobOper.Company
and JobAsmbl.JobNum = JobOper.JobNum
and JobAsmbl.AssemblySeq = JobOper.AssemblySeq
and ( JobOper.OprSeq <= @ThruOp )
left outer join Erp.JobMtl as [JobMtl] on
JobOper.Company = JobMtl.Company
and JobOper.JobNum = JobMtl.JobNum
and JobOper.AssemblySeq = JobMtl.AssemblySeq
and JobOper.OprSeq = JobMtl.RelatedOperation
inner join Erp.JobOpDtl as [JobOpDtl] on
JobOper.Company = JobOpDtl.Company
and JobOper.JobNum = JobOpDtl.JobNum
and JobOper.AssemblySeq = JobOpDtl.AssemblySeq
and JobOper.OprSeq = JobOpDtl.OprSeq
where (JobHead.JobNum = @MyJob)
group by
[JobOper].[JobNum],
[JobHead].[PartNum],
[JobOper].[AssemblySeq],
[JobAsmbl].[RequiredQty],
[JobAsmbl].[PartNum],
[JobOper].[OprSeq],
[JobOper].[OpDesc],
[JobOper].[ActProdHours],
[JobOper].[ActSetupHours],
[JobOper].[SubContract],
[JobOper].[ActLabCost],
[JobHead].[ProdQty],
[JobOper].[QtyCompleted],
[JobOper].[RunQty],
[JobOper].[QtyPer],
(iif(JobOper.QtyCompleted=0,0,JobOper.QtyCompleted)),
(iif(MyQty=0,0,iif(JobOper.SubContract=0, JobOper.ActLabCost/ MyQty, 0))),
(iif(MyQty=0,0,iif(JobOper.SubContract=1, JobOper.ActLabCost/ MyQty, 0))),
(iif(MyQty=0,0,JobOper.ActBurCost / MyQty))) as [SubQuery1]
ScrapCosting.baq (28.9 KB)
Here’s the BAQ file…
In the example above the last column should be my total. You can see only one row where it calculates correctly. The others are missing data comepltely.
I even moved my total to a subquery to make sure that grouping wasn’t causing any problems. This seems like a bug to me. Anyone else found an issue like this? What can we do to fix it?

