Localizing Eventhouse dashboards with KQL unit conversions

In my parcel-tracking post, I’ve used Fabric Eventhouse to reconstruct deliveries and put them on a map. There’s a smaller detail when that data reaches users: some expect kilometers and Celsius, others miles and Fahrenheit.

KQL’s unit conversion functions, introduced in Shaf Mahmood’s 2022 post, handle those conversions. Let’s use them to add a measurement selector to an Eventhouse-backed dashboard.

Keeping a common unit

I’d keep consistent units in Eventhouse – meters, kilograms, and degrees Celsius – and convert when preparing the query results for display. If sources send different units, normalize them before aggregating. Adding miles to kilometers and converting the total afterwards won’t fix the total.

The functions take a value, a source unit, and a destination unit. convert_length() handles distances; similar functions cover temperature, mass, speed, and volume. Use documented identifiers such as "Kilometer" in the conversion, not display labels such as "km".

Adding a unit selector

Open a KQL queryset connected to a KQL database in your Eventhouse. I’ve kept this synthetic delivery sample inline, so there’s nothing to ingest. Each row contains an incremental distance traveled (not a cumulative odometer reading) and a temperature observation.

Here’s the complete query:

let _unitSystem = "US";
let DistanceTarget = iff(_unitSystem == "US", "Mile", "Kilometer");
let TemperatureTarget = iff(
    _unitSystem == "US", "DegreeFahrenheit", "DegreeCelsius");
datatable(Route:string, DistanceMeters:real, TemperatureCelsius:real)
[
    "Route A", 10000.0, 4.0,
    "Route A", 15000.0, 6.0,
    "Route B",  8000.0, 2.0
]
| where assert(
    _unitSystem in ("Metric", "US"),
    "Unsupported unit system. Use Metric or US.")
| summarize
    TotalDistanceMeters = sum(DistanceMeters),
    AverageTemperatureCelsius = avg(TemperatureCelsius)
    by Route
| project
    UnitSystem = _unitSystem,
    Route,
    Distance = round(
        convert_length(TotalDistanceMeters, "Meter", DistanceTarget), 2),
    DistanceUnit = iff(_unitSystem == "US", "mi", "km"),
    AverageTemperature = round(
        convert_temperature(
            AverageTemperatureCelsius, "DegreeCelsius", TemperatureTarget), 1),
    TemperatureUnit = iff(_unitSystem == "US", "°F", "°C")
| order by Route asc

With "US" selected, the result is:

UnitSystemRouteDistanceDistanceUnitAverageTemperatureTemperatureUnit
USRoute A15.53mi41°F
USRoute B4.97mi35.6°F

Change the first line to "Metric" and Route A becomes 25 km and 5 °C; Route B becomes 8 km and 2 °C. Same source rows, different presentation.

We sum distances and average temperatures before converting. That’s valid for these calculations and avoids converting every input row. The average is a simple average of observations, not a time-weighted one.

The assert() rejects unsupported selections rather than silently falling back to metric units. Nothing fancy here, but I’d rather see an error than the wrong measurements.

Connecting the dashboard

In a Fabric Real-Time Dashboard:

  1. Connect a tile to your Eventhouse KQL database and open the parameter editor in editing mode.
  2. Add a Single selection parameter with variable name _unitSystem, data type String, and source Fixed values. Use Metric and US, displayed as Metric and US customary. Choose a default and disable Select all.
  3. Paste the query into the tile and remove let _unitSystem = "US";. The dashboard supplies the selection. Start with a table visual to show the values alongside their units.

Only queries referencing the parameter respond to it. When replacing the sample with real telemetry, filter the event timestamp using _startTime and _endTime before aggregating.

Check the visual labels too. Returning DistanceUnit doesn’t automatically update an axis title; a chart showing miles under a “km” heading isn’t localized correctly.

Finishing the localization

Supporting selectable units is part of internationalization. Choosing the units, labels, and number formatting for an audience is localization – and KQL only handles the measurement conversion.

For an application-generated report, replace the first let with declare query_parameters(_unitSystem:string = "Metric");. Bind the selection through SDK or REST query parameters, not string concatenation.

Keep the returned values numeric and their units separate. Let the presentation layer translate labels and format numbers. The example rounds for final display; return unrounded values if the report needs further calculations.

I’d also keep measurement preferences separate from language. An English-speaking user might want kilometers and Celsius; a UK report might combine miles with Celsius.

A few details worth keeping in mind:

  • Invalid conversion units return null. Use "Mile", not "Miles", and don’t turn failed conversions into zeros.
  • convert_temperature() converts readings, not temperature changes. A reading of 10 °C is 50 °F; an increase of 10 °C is an increase of 18 °F.
  • US customary and imperial aren’t interchangeable. convert_volume() distinguishes "UsGallon" from "ImperialGallon".

I’d start with that: one consistent dataset in Eventhouse, explicit unit preferences, and labels that stay attached to the numbers.