Why Do These NRQL Queries Return Different Results?

FROM Metric
SELECT cardinality('myMetric.count.value') timeseries until 5 minutes ago

FROM Metric
SELECT cardinality() facet metricName
WHERE metricName = 'myMetric.count.value' timeseries until 5 minutes ago

These appear to be the same query written in a different way, but I get wildly different results depending on which I run. What am I missing?

Hi @tbrammer.cont! I believe it is the FACET clause that is causing you issues here as it is the main difference between both your queries. Use FACET to separate and group your results by attribute values. For example, you could FACET your PageView data by deviceType to figure out what percentage of your traffic comes from mobile, tablet, and desktop devices.

Let me know if this makes sense in regards to your use case.

Hi Neal,

I’ll update this one with the solution that I finally came too. The cardinality function has an undocumented syntax requirement that the metric name be provided with backtics - “`” rather than double or single quotes. The reason for the difference is that the facet query was correctly returning only the cardinality of “myMetric.count.value” whereas the top query was returning the cardinality of all the metrics in the account.

cardinality('myMetric.count.value') This is actually a syntax error, but rather than failing it actually just runs - cardinality()

1 Like