Forum Discussion

cchilton's avatar
cchilton
Helper I
1 year ago
Solved

Multiple dataViewMappings

I'm building a custom KPI table visual that includes a sparkline. To render the sparkline, I need the raw (unaggregated) data by date. However, I also need aggregated totals to display in a separate ...
  • cchilton's avatar
    1 year ago

    This work around worked for me. This approach makes the aggregatedTotals measure repeat the same total for each date row — so you can show both the sparkline and the overall KPI side-by-side.

    1. Create a DAX measure for the aggregate over a fixed date range (I used variables instead of hardcoded dates):

    TotalBetweenDates =
    CALCULATE(
    [Total],
    FILTER(
    ALL('Date'),
    'Date'[Date] >= DATE(2025,1,1) && 'Date'[Date] <= DATE(2025,3,31)
    )
    )

     

    2. Add the new data role in capabilities.json:

    {
    "displayName": "Aggregated Totals",
    "name": "aggregatedTotals",
    "kind": "Measure"
    }

     

    3. Include the aggregate measure in your dataViewMappings:

    "dataViewMappings": [
    {
    "categorical": {
    "categories": { "for": { "in": "metric" } },
    "values": {
    "group": {
    "by": "date",
    "select": [
    { "for": { "in": "total" } },
    { "for": { "in": "target" } },
    { "for": { "in": "kpi" } },
    { "for": { "in": "aggregatedTotals" } }
    ]
    }
    }
    }
    }
    ]