BAQ to only get the latest quote date

I am trying to make a BAQ to get the latest quote that was entered for each part for a certain customer, and I am having trouble getting it working. I searched this site, and I found some threads that seemed similar, but none of the solutions there solved my issue.

I managed to get the baq to throw out all the parts for the customer, along with the date that they were quoted, but it is showing all quotes, not just the latest. At first, I tried to just do result set row distinct, then top, then top distinct, but none of those removed the old quotes.

Then I tried making a subquery, and that did not seem to work either. The query has QuoteHed.QuoteNum, .Company, .CustNum, and .DateQuoted all as group by.

I added a calculated field called LastDate that should only return the maximum date from QuoteHed.DateQuoted, but that also did not work.

What am I missing here?

You are on the right track. Create a SubQuery with QuoteDtl and QuoteHed with the fields, QuoteDtl.Company, QuoteHed.CustNum, QuoteDtl.QuoteNum, QuoteDtl.PartNum, and QuoteHed.DateQuoted. For your Top Level, use your SubQuery as the data source and GroupBy fields, Company, Cust Num, and Part Number, and create a Calculated field that is max(SubQuery1.QuoteHed_DateQuoted). This should give you what you need.

1 Like

I think you can do this with the calculated field approach, just need to make sure on the display columns screen you select the Group By on Part.

See below, I’ve brought in the QuotHed table to get the quoted date.

A quick test and it seemed to work for me - you may need to filter out blank dates (if you have quotes created but not ticked as ‘Quoted’)

But I’m not an expert, sure someone will point out if there’s a better way.

I am trying this, and it does not seem to be working. I am grouping by only the fields you say, but I get the error saying that quotenum is not contained in either an aggregate function or the group by clause. If I add that one to the group by, then it says the same thing for DateQuoted. Grouping by both of those does allow me to make the calculated field max(SubQuery2.QuoteHed_DateQuoted) and add it to my baq. However, this still shows all of the old quotes that we have.

Is your calculated field in your subquery? Or your top level? It should be in the subquery, not the top level.

It was on the top subquery, I moved it to the second subquery and I am still getting the same thing.

You can’t show the field that you are trying to get the max of.

Take a second to breathe and think about what you are doing here.

The group by will group all of the rows that have the same values in all of the rows that are shown. If you show every date, then that row is unique, and it won’t be grouped, hence why you are getting all of them.

2 Likes

Try removing the Quote Number and Quote Date from the display fields.

1 Like

Also, I don’t understand how you can have different dates for the same quote???

Each quote, which you have uniquely identified by the quote number, is going to have one date.

So yeah, what @bruce6s said.

Also, another technique, depending on what you are actually trying to do here, is to use a windowing function, which will not require a subquery.

max( quote.date) over (partition by PartNum, Customer, whatever else you want to chop it up by, order by quote.date)

What this will do is if you have grid of all of your quotes, will look at the windows and give you an aggregate value. It will still keep all of the rows, but you can get the max.

Example.

Quote Customer Part Number Date Max (by part,cust) Reason
100 acme a1 1/1/2024 2/5/2024 same part (A1) and customer
101 acme a1 2/5/2024 2/5/2024 same part (A1) and customer
102 acme a2 1/6/2024 5/10/2024 same part (A2) and customer
103 acme a2 5/10/2024 5/10/2024 same part (A2) and customer
104 Spacely a1 3/10/2024 3/10/2024 Different customer and part
105 Spacely a2 4/8/2024 4/8/2024 Different customer and part
2 Likes