This is what I am trying to achieve.
View attachment 114429
a loop (i think) through each date and perform the analysis then move to next date and perform same operation on that day
then move to next date.
I hope that makes sense
I see, you took the Northwind data and converted the date/time values to midnight on that date. And then, in post #9 you updated the question from date filtering to focus on something else other than the dates.
I'm a bit unclear how this gives you useful data. Are you looking for the highest Unit price for an product in each order, regardless of the number of units of any product? That's all this data can produce. And the sum of unit prices for products in an order seems like a fairly obscure data point. If you order 100 units of a product priced at $1.00 per unit, and 1 unit of a product priced at $100 per unit, your sum will return $101 as the sum of unit price. The order total, though, would be $200 altogether-- (1 X 100) + (100 X 1). What purpose does this calculation serve?
And ranking those orders by the sum of unit prices? What business purpose does that serve?
I was on the team that created the Northwind Developer (and Starter) version templates for Microsoft, so I'm reasonably familiar with the data, but the business purpose of this ranking on Sum of Unit Price wasn't one of the things we thought of. Help me understand the goal.
I think the ranking you want will need to be done in a couple of queries, no looping required, but it'll help to put this into some real world context in case I'm misunderstanding something.