Here is the second demo ( Thanks to Kenneth Puggaard).
Kevin, the Sales Manager wants to see the number of sales orders, open orders and back orders for each customer along with other customer information. In the first demo , we displayed the customer information directly from CustTable. In this demo , we are going to use AX data programmability to get count of sales orders for each customer and display it in the same web page.
 Open AOT and navigate to the datasource of the webform that you want to add these aggregate information. Expand the Datasource node of the web form and select CustTable. Right click on the Methods sub node and select new method. Copy the text from below ( one method at a time) and create the below three display methods on the data source. Once it is done, then the same way as you did drag-n-drop of fields from CustTable to the WebGrid, you can drag-n-drop the display methods on to the webgrid to add these columns.

Go to Enterprise Portal and Refresh AOD to clear the cache. Now when you navigate to the web page that contains the webform,  you will see these additional columns in the grid seamlessly rendering the values alongside information from the customer table.


display NumberOfRecords BackOrders()
{
    SalesTable salesTable;
    ;
    select count(recId) from salesTable
        where salesTable.InvoiceAccount == custTable.AccountNum &&
              salesTable.SalesStatus == SalesStatus::Backorder &&
              salesTable.DeliveryDate < today()-1;

    return salesTable.RecId;
}

display NumberOfRecords NoSalesOrders()
{
    SalesTable salesTable;
    ;
    select count(recId) from salesTable
        where salesTable.InvoiceAccount == custTable.AccountNum &&
              salesTable.SalesStatus    == SalesStatus::Backorder ||
              salesTable.SalesStatus    == SalesStatus::Delivered ||
              salesTable.SalesStatus    == SalesStatus::Invoiced;

    return salesTable.RecId;
}

display NumberOfRecords openSalesOrders()
{
    SalesTable salesTable;
    ;
    select count(recId) from salesTable
        where salesTable.InvoiceAccount == custTable.AccountNum &&
              salesTable.SalesStatus == SalesStatus::Backorder ||
              salesTable.SalesStatus == SalesStatus::Delivered;

    return salesTable.RecId;
}