# "Calculated field not found" in sub-query

**URL:** <https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874>\
**Category:** Epicor ERP 10\
**Tags:** baq\
**Created:** [January 23, 2020, 4:48pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874 "2020-01-23T16:48:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Epicorus](https://www.epiusers.help/user_avatar/www.epiusers.help/epicorus/32/12102_2.png) [@Epicorus](https://www.epiusers.help/u/Epicorus)\
**Post date:** [January 23, 2020, 4:48pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/1 "2020-01-23T16:48:09Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![jeromy](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/ecccb3/32.png) [@jeromy](https://www.epiusers.help/u/jeromy)\
**Post date:** [January 23, 2020, 4:52pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/2 "2020-01-23T16:52:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Epicorus](https://www.epiusers.help/user_avatar/www.epiusers.help/epicorus/32/12102_2.png) [@Epicorus](https://www.epiusers.help/u/Epicorus)\
**Post date:** [January 23, 2020, 4:58pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/3 "2020-01-23T16:58:43Z")

</div>

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"
```

---

<div class="post-metadata">

**Author:** ![utaylor](https://www.epiusers.help/user_avatar/www.epiusers.help/utaylor/32/64664_2.png) [@utaylor](https://www.epiusers.help/u/utaylor)\
**Post date:** [January 23, 2020, 5:06pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/4 "2020-01-23T17:06:26Z")

</div>

will you post the whole query?

---

<div class="post-metadata">

**Author:** ![Epicorus](https://www.epiusers.help/user_avatar/www.epiusers.help/epicorus/32/12102_2.png) [@Epicorus](https://www.epiusers.help/u/Epicorus)\
**Post date:** [January 23, 2020, 5:13pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/5 "2020-01-23T17:13:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utaylor](https://www.epiusers.help/user_avatar/www.epiusers.help/utaylor/32/64664_2.png) [@utaylor](https://www.epiusers.help/u/utaylor)\
**Post date:** [January 23, 2020, 6:05pm UTC](https://www.epiusers.help/t/calculated-field-not-found-in-sub-query/63874/6 "2020-01-23T18:05:13Z")

</div>

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.
