Top Query Duration sorting by Text values and not numeric values

While reviewing the Idera SQL DM Performance Insights extension in Azure Data Studio, the top query duration chart is sorting by text values instead of numeric values. Using the run query option of the chart, the following query is used:

SELECT
    [SQL Instance] = mss.InstanceName,
    [Database] = d.DatabaseName,
    [DateTime Collected] = dateadd(mi, @UTCOffset, qm.UTCCollectionDateTime),
    [Duration (ms)] = format(qm.DurationMilliseconds,'N0'),
    [CPU (ms)] = format(qm.CPUMilliseconds,'N0'),
    [Reads] = format(qm.Reads,'N0'),
    [Writes] = format(qm.Writes,'N0'),
    [SQL Text] = s.SQLSignature,
s.SQLSignatureID
FROM dbo.MonitoredSQLServers mss (nolock)
    JOIN dbo.SQLServerDatabaseNames d (nolock) ON d.SQLServerID = mss.SQLServerID
    JOIN dbo.QueryMonitorStatistics qm (nolock) ON qm.DatabaseID = d.DatabaseID
    JOIN dbo.AllSQLSignatures s (nolock) on qm.SQLSignatureID = s.SQLSignatureID
WHERE mss.Active = 1
    and dateadd(mi, @UTCOffset, qm.UTCCollectionDateTime) between @StartDate and @EndDate
ORDER BY [Duration (ms)] DESC
The format function changes the numeric value of qm.DurationMilliseconds to nvarchar data type so that a duration of 999 is before a duration of 392866.
Updating the query to remove the format function correctly sorts the results and returns the top queries by duration.