Hi David,
You can determine the top customer by sales value using a combination of microflows and database retrievals without needing OQL.
First, retrieve all sales records associated with the logged-in salesperson. Then, create a non-persistable entity (e.g., CustomerSalesSummary
) with attributes for the customer and total sales value. In a microflow, loop through the sales records, sum up the total sales per customer, and store the results in this entity. Once you have the aggregated data, sort the list in descending order based on total sales value. The first entry in this sorted list will be the top customer.
If you also want to show the top 10 customers when the salesperson clicks on the top client widget, simply retrieve the first 10 items from the sorted list and display them in a list view or data grid.
This approach keeps things simple and avoids the complexity of OQL while still being efficient. However, if you’re working with a large dataset and need better performance, you can consider using XPath or OQL queries.
Let me know if you need any further clarification!
Hope it helps!
Hi David,
I think you can achieve this in Mendix by avoiding OQL unless you have a very compelling reason to use OQL, the Aggregate activity within a microflow is the best solution. You can simply retrieve sales, aggregate by customer (summing sales value), create a non-persistable entity for totals, and populate it in a loop then on click, a microflow retrieves/aggregates again, sorts, and opens a page with a data grid (page size 10) for the top 10 customers.
Hope it will help you.