I need to select GLJrnDtl records with the following odd criteria
It must select all the records for a certain date EXECPT those records where all the GLAccount for the ARInvoiceNum are the same.
Here’s an example of the data in the GLJrnDtl table
I want the BAQ to exclude rows for invoice 3456 because all the entries are for the same GL Acct.
I can hide these rows when the report renders by using CountDistinct(), but their values still add up into other aggregates (like SUM() ), which I don’t want.
How do I even make a simple BAQ that only selects records where all the records of a group of records (my outer group here is ARInvoiceNum) have the same value for one field (the field being GLAccount)?
If you can use straight SQL and maybe do it via external query, if your current version of Epicor doesn’t allow SQL in BAQ (i.e., we have 905702, i understand there is new capability in E10 with BAQs but don’t know details), would something like this work?
SELECT ARInvoiceNum, JournalNum, JournalLine, PostedDate, COUNT(GLAccount) AS Expr1
FROM GLJrnDtl
WHERE (PostedDate > ‘01/01/2014’)
GROUP BY ARInvoiceNum, JournalNum, JournalLine, PostedDate
Having Count(*) = 1
You can create an inner subquery that does a group by on ARInvoiceNum and GLAcct. Add a calculated field that provides a row count. COUNT(*)
Create a top level query that joins the table to the inner subquery on ARInvoiceNum and GLAcct. Apply criteria to only select inner subquery rows where rowcount = 1.