Add custom column to Magento report and sales dashboard

Add custom column to Magento report and sales dashboard

August 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add custom column to Magento report and sales dashboard

Customizing Magento Reports for Post-Discount Tracking

As an online retailer, tracking sales accurately is crucial for your accounting department’s peace of mind. However, when customers receive discounts after the fact due to product issues or other reasons, the default Magento reports can fall short in providing the exact final amount charged.

The Challenge: Capturing Net Sales After Adjustments

Let’s break down the issue at hand:

  1. A customer places an order for $100 with a $10 shipping fee.
  2. They receive a 30% discount after noticing a scratch on the product, resulting in a credit memo of $30.
  3. The accounting department needs to see the final amount charged ($80) separately from other reports.

The problem lies in Magento’s default reporting system not capturing these post-order adjustments effectively. While you can use sales_order_grid for basic order management, it lacks the flexibility needed for custom calculations like net sales after discounts and refunds.

An Effective Solution: Extending Existing Reports

To solve this issue, we’ll need to extend Magento’s existing report models and views with new calculated fields. Here’s a step-by-step approach:

Step 1: Create a New Model

Create a new model (e.g., Vendor_Module_Model_Sales_Report_Net_Sales) that inherits from the base report model (Magento\Sales\Model\ResourceModel\Order\Grid). This allows you to override and extend the default grid functionality.

Step 2: Override the Grid Collection

In your new model, override the _initSelect() method to add a new column for the “net sales” amount. You’ll need to join the sales_creditmemo_grid table and calculate the final figure:

protected function _initSelect()
{
    $select = parent::_initSelect();
    $select->joinLeft(
        ['cm' => $this->getTable('sales/creditmemo_grid')],
        'main_table.entity_id = cm.order_id',
        [
            'discounted_total' => new Zend_Db_Expr('IFNULL(SUM(cm.grand_total), 0)')
        ]
    );
    $select->columns(['net_sales' => new Zend_Db_Expr('IFNULL(main_table.base_grand_total - SUM(cm.grand_total), 0)')]);
    return $select;
}

In this example, we’re joining the credit memo table and calculating the net sales as the original grand total minus the sum of all applied discounts.

Step 3: Update the Report View

Next, you’ll need to update your report view (e.g., Vendor_Module_Block_Sales_Report_Net_Sales) to display this new column:

<column name="net_sales" index="net_sales">
    <arguments>
        <argument name="header" translate="true">Net Sales</argument>
        <argument name="width" translate="true">100</argument>
    </arguments>
</column>

Step 4: Add the Report to the Dashboard

Finally, you’ll need to add this new report to your admin dashboard or create a new page for it. This involves updating the adminhtml.xml layout file and adding the necessary menu items.

Best Practices and Next Steps

  1. Use Magento’s Default Reporting Framework: By extending existing models and views, you’re ensuring compatibility with future Magento updates.

  2. Test Thoroughly: Make sure to test your solution across different scenarios, including multiple discounts and partial refunds.

  3. Performance Optimization: If the number of orders is very high, consider using Magento’s EAV indexing for better performance.

Conclusion

Customizing Magento reports requires a deep understanding of the core reporting system. By extending existing models and views, we can create new columns that reflect post-discount sales figures accurately.

Remember to follow best practices and keep your solution compatible with future updates. If you need further assistance or want to explore how custom development can optimize your business processes, feel free to contact us at https://laravelcompany.com.

Catalog Extensions Admin Orders

Our network