"Calculated field not found" in sub-query

I’m trying to create a sub-query in a BAQ that does a GROUP BY and then has the SUM of one of the fields which is supposed to be exposed to the parent query.

I created the query by itself in a BAQ and it works perfectly. I then went into an existing BAQ and recreated it as a sub-query and have joined it in the top-level query. But when I go to Analyze it I get the error:

"Calculated field not found"

I don’t know what to make of this. What does this mean? The subquery potion of the “Query Phrase” looks like this:

inner join  (select 
[InvcTax1].[InvoiceNum] as [InvcTax1_InvoiceNum],
[InvcTax1].[Company] as [InvcTax1_Company],
(SUM(InvcTax1.DocTaxAmt)) as [Calculated_SumDocTaxAmt]
from Erp.InvcTax as InvcTax1
group by [InvcTax1].[InvoiceNum])  as SubQuery2 on 
InvcDtl.Company = SubQuery2.InvcTax1_Company
and InvcDtl.InvoiceNum = SubQuery2.InvcTax1_InvoiceNum

I see you grouped by InvoiceNum but not Company. Try adding Company to your group by.

1 Like

Thank you for the suggestion. It does not make any difference.

....
group by [InvcTax1].[InvoiceNum],
[InvcTax1].[Company])  as SubQuery2 on 
....

still results in

"Calculated field not found"

will you post the whole query?

It’s a huge query (16 tables) so I’ve tried to limit to just the relevant pieces of information. However, I did realize that I have omitted the part of the top-level select which should be showing the relevant fields of the sub-query. Here it is:

select
    <<omitted 54 lines for brevity>>
    [SubQuery2].[InvcTax1_InvoiceNum] as [InvcTax1_InvoiceNum],
[SubQuery2].[Calculated_SumDocTaxAmt] as [Calculated_SumDocTaxAmt]
from ...

These appear to match what the calculated field is called in the sub-query.

I have ran into this when I delete a calculated field that I was using in another calculated field or in a group by at some point in time.

2 Likes