I must do a BAQ that shows me the last 6 costs

I must do a BAQ that shows me the last 6 costs of each part, it must be from the PODetail table to obtain the details of each part purchased. I have tried and the query gives me all the results, I did a TOP 6 but it only gives 6 records. any ideas?

I figure an example would be easier to show you how to do it rather than try to tell you through the forum. The important thing is to add a calculation column in the CTE.

ROW_NUMBER() OVER (PARTITION BY [group by item - PartNum] order by [order column - PONum or PO Date] DESC ) as [Calculated_RowNumber]

TopSix.baq (21.4 KB)

Then the main query you can just limit to Calculated_RowNumber<= 6.

5 Likes

Just curious how you will be using this data?

I worked on a similar query for analysis a while back
In that case I included start date and partnum filters,
returning a new row for the part whenever the price differed from the prior.
For the most part it worked except… I had to handle a few odd PO’s.

Good morning, I could not import since your version is more recent, I have version 10.2.4 I get this error.

image

If you can send me pictures of the confguration to the intern please.

Thank you so much

Sorry, I’m in the middle of an implementation. If I can get some snapshots I will ASP.