TX Sheet Control

PivotTable.GetDataAsync Method

Method
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server as TXTextControl.TXSheetControl.Api.dll from the private NuGet feed or the supplied NuGet folder
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll

Returns an aggregate by value caption and optional row/column paths; parent paths select totals.

Syntax

public Task<double?> GetDataAsync(string valueField, object?[]? rowPath = null, object?[]? columnPath = null, CancellationToken cancellationToken = default);

Return Value

The underlying numeric aggregate from the last refreshed cache, without Show Values As transformations. An intersection with no source records returns null; records that aggregate to zero return 0. A statistic without enough observations also returns null. Empty/error replacement captions affect the visible report rather than this aggregate API. Use the result matrix or GETPIVOTDATA to read the visible display value.

Example

Place this code in a .NET console application that references the server package. It creates source orders and a report before applying the setting or operation.

using TXTextControl.TXSheetControl.Server;

await using var control = new ServerSheetControl();
var workbook = control.Workbook;
var source = await workbook.Sheets.AtAsync(0);
await source.Range("A1:D5").SetValuesAsync([
    ["Region", "Category", "Revenue", "Cost"],
    ["Europe", "Software", 1250, 500], ["Europe", "Services", 700, 350],
    ["Americas", "Software", 1800, 900], ["Americas", "Services", 950, 400]
]);
var report = await workbook.Sheets.AddAsync("Sales Pivot");
var pivot = await report.PivotTables.AddAsync(new PivotTableOptions {
    Name = "RegionalSales", Source = new() { SheetId = source.Id, Range = "A1:D5" },
    Destination = new() { SheetId = report.Id, Cell = "B3" },
    Rows = [new() { Field = "Region" }], Columns = [new() { Field = "Category" }],
    Values = [new() { Field = "Revenue", Caption = "Sales", NumberFormatCode = "$#,##0.00" }]
});

await report.Cell("B12").SetTextAsync("European revenue");
await report.Cell("C12").SetValueAsync(await pivot.GetDataAsync("Sales", ["Europe"]));

See Pivot Tables for cache semantics, grouping, supported values and limits. Partial updates use camelCase anonymous objects; creation uses complete PivotTableOptions.