Epicor BAQ SUM syntax

Hello everyone,

I have recently come a long way in my epicor journey. I have been editing some BAQ’s which I found are the key to figuring out everything to do with reports.

While trying to create a report where I want to get a total of purchases made from each of our clients I am running into a snag with the SUM function while making a calculated field. I ran a sum of the InvcDtl.CustExtPrice field, however it seems to just print the same value as the CustExtPrice field. I think this makes sense since it would just sum one value, but how would I get the sum to actually calculate the total of all the Price fields for each company? For example my table would look like this

-----------|------------|------------
1728.30|1738.30 | Cust1
1258.10|1258.10 | Cust1
500.20 |500.20 | Cust2

300.20 300.20 Cust2

however I would want it to look like this instead.

-----------|------------|------------
1728.30|1738.30 | Cust1
1258.10|2996.40 | Cust1
500.20 |500.20 | Cust2

300.20 800.20 Cust2

Hope that works as an example, but any help would be greatly appreciated!

Try using a window function:

Sum( InvcDtl.CustExtPrice ) OVER (Partition By Customer.CustID)

This will do the Summation per CustID which I believe is what you’re looking for.

2 Likes

That worked like a charm, thank you! Any idea where I could learn the syntax for functions used in calculated fields? I know it runs of sql code but it seems to not accept code that I write using the sql syntax so any idea where I could learn what works in epicor and what doesnt? I am sure I will run into another time when I don’t know the syntax for functions, and I would love to learn more.

BAQ “calculated field” should be able to use most T-SQL syntax to query data. It won’t let you write back to the SQL server. What ones are you having problems with?

When I was trying to search up the syntax for Sum for example it said I can use FROM and Where condition, but that gave me an error when I input that into the calculated field. Maybe I am misunderstanding something simple since I am new to SQL but it gave me an error when I input that stating I had incorrect syntax with the FROM keyword.

The FROM keyword is already taken care of by the BAQ so you don’t need to include it in a calculated field --except for some advanced needs.