Reporting expressions

Expressions use field tokens such as {Customer.Name}. They can be used by text templates, formula fields, aggregates, running totals, and formula-enabled properties.

Formula fields

Formula fields create reusable calculated values that appear in the field explorer and can be dropped onto the report.
<Report Data="@invoice"
        Editable
        PreviewFormats="ReportPreviewFormat.Html | ReportPreviewFormat.Pdf">
    <ReportViewer PreviewFormat="ReportPreviewFormat.Html | ReportPreviewFormat.Pdf"
                  DefaultPreviewFormat="ReportPreviewFormat.Html" />
    <ReportDataSources>
        <ReportObjectDataSource Name="Invoice" Data="@invoice" />
    </ReportDataSources>
    <ReportFormulaFields>
        <ReportFormulaField Name="CustomerSummary" Formula="'Customer: ' + {Customer.Name}" />
        <ReportFormulaField Name="LargeLine" Formula="if {Lines.Total} > 500 then 'Large' else 'Standard'" />
    </ReportFormulaFields>
    <ReportPage Name="Invoice">
        <ReportHeader Name="Invoice header" Height="72">
            <ReportText Text="Formula fields" X="30" Y="18" Width="240" Height="24" FontSize="18" Bold FontColor="@ReportColors.Blue" />
            <ReportField Field="CustomerSummary" X="30" Y="45" Width="300" Height="18" />
        </ReportHeader>
        <ReportPageHeader Name="Column headers" Height="32">
            <ReportText Text="Description" X="30" Y="8" Width="240" Height="18" Bold />
            <ReportText Text="Total" X="300" Y="8" Width="90" Height="18" Bold TextAlignment="TextAlignment.End" />
            <ReportText Text="Formula result" X="420" Y="8" Width="90" Height="18" Bold />
        </ReportPageHeader>
        <ReportDetail Name="Invoice lines" Height="30" DataSource="Invoice.Lines">
            <ReportField Field="Description" X="30" Y="6" Width="240" Height="18" />
            <ReportField Field="Total" Format="@ReportFormats.Currency()" X="300" Y="6" Width="90" Height="18" />
            <ReportField Field="LargeLine" X="420" Y="6" Width="90" Height="18" Bold />
        </ReportDetail>
    </ReportPage>
</Report>
@code {
    private readonly InvoiceReportModel invoice = new()
    {
        Customer = new()
        {
            Name = "Northwind Traders",
        },
        Lines =
        [
            new() { Description = "Implementation workshop", Total = 640.50m },
            new() { Description = "Reporting module license", Total = 500.00m },
            new() { Description = "Priority support", Total = 100.00m },
        ],
    };

    private sealed class InvoiceReportModel
    {
        public InvoiceCustomerModel Customer { get; set; }

        public List<InvoiceLineModel> Lines { get; set; } = [];
    }

    private sealed class InvoiceCustomerModel
    {
        public string Name { get; set; }
    }

    private sealed class InvoiceLineModel
    {
        public string Description { get; set; }

        public decimal Total { get; set; }
    }
}

Aggregates and running totals

Aggregates summarize a field at render time. Running totals accumulate values as detail rows are rendered.
<Report Data="@invoice"
        Editable
        PreviewFormats="ReportPreviewFormat.Html | ReportPreviewFormat.Pdf">
    <ReportViewer PreviewFormat="ReportPreviewFormat.Html | ReportPreviewFormat.Pdf"
                  DefaultPreviewFormat="ReportPreviewFormat.Html" />
    <ReportDataSources>
        <ReportObjectDataSource Name="Invoice" Data="@invoice" />
    </ReportDataSources>
    <ReportRunningTotals>
        <ReportRunningTotal Name="LineRunningTotal"
                            DataSource="Invoice.Lines"
                            Field="Total"
                            AggregateFunction="ReportAggregateFunction.Sum" />
    </ReportRunningTotals>
    <ReportPage Name="Invoice">
        <ReportHeader Name="Invoice header" Height="60">
            <ReportText Text="Running totals" X="30" Y="18" Width="240" Height="24" FontSize="18" Bold FontColor="@ReportColors.Blue" />
        </ReportHeader>
        <ReportPageHeader Name="Column headers" Height="32">
            <ReportText Text="Description" X="30" Y="8" Width="210" Height="18" Bold />
            <ReportText Text="Total" X="300" Y="8" Width="90" Height="18" Bold TextAlignment="TextAlignment.End" />
            <ReportText Text="Running total" X="420" Y="8" Width="90" Height="18" Bold TextAlignment="TextAlignment.End" />
        </ReportPageHeader>
        <ReportDetail Name="Invoice lines" Height="30" DataSource="Invoice.Lines">
            <ReportField Field="Description" X="30" Y="6" Width="210" Height="18" />
            <ReportField Field="Total" Format="@ReportFormats.Currency()" X="300" Y="6" Width="90" Height="18" />
            <ReportField Field="LineRunningTotal" Format="@ReportFormats.Currency()" X="420" Y="6" Width="90" Height="18" Bold FontColor="@ReportColors.Green" />
        </ReportDetail>
        <ReportFooter Name="Totals" Height="45">
            <ReportLine X="30" Y="6" Width="480" Height="8" Thickness="1" />
            <ReportText Text="Grand total" X="300" Y="18" Width="105" Height="18" Bold />
            <ReportField Field="Lines.Total" AggregateFunction="ReportAggregateFunction.Sum" Format="@ReportFormats.Currency()" X="420" Y="18" Width="90" Height="18" Bold FontColor="@ReportColors.Green" />
        </ReportFooter>
    </ReportPage>
</Report>
@code {
    private readonly InvoiceReportModel invoice = new()
    {
        Lines =
        [
            new() { Description = "Implementation workshop", Total = 640.50m },
            new() { Description = "Reporting module license", Total = 500.00m },
            new() { Description = "Priority support", Total = 100.00m },
        ],
    };

    private sealed class InvoiceReportModel
    {
        public List<InvoiceLineModel> Lines { get; set; } = [];
    }

    private sealed class InvoiceLineModel
    {
        public string Description { get; set; }

        public decimal Total { get; set; }
    }
}

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.

On this page