Display the invoice number with the largest number

Hello everyone,

I’m trying to create the sales order status in BAQ. I also want to add the invoice number for each order line. As you all know, the invoice for the order line may be credited and another invoice may be created again. So if I have multiple invoices and I link the invoice number in the invoice head, it will create duplicate order lines equal to the invoice quantity.
So the way I was thinking was that only the highest invoice number for that order line would appear. Because our invoice number is an automatic sequence. When I do that, the latest invoice will appear.
But I don’t know how to create this SQL. Can someone please tell me how to create it?
Thanks in advance!

You can use the max() function to take the highest number from a number variable. So, your formula would just be:

max(InvcHead.InvoiceNum) //or whatever your invoice number field is.

Note that this is an aggregate function, so it may need some groupings depending on what else you have in the output or subqueries.

2 Likes

Instead of showing just the maximum invoice number.
Why not a list of them?
Enter this as a NChar type calculated field on the BAQ.

STRING_AGG(InvcHead.InvoiceNum, ', ')

@NateS offered this in another post.

1 Like

That’s interesting. The direct answer to my question is NateS’ answer, but I would like to apply this Way.

1 Like