question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

the error message for using dimensions within a non-aggregate metric isn't clear

See original GitHub issue

How I got here…

I tried to aggregate a dimension within a non-aggregate metric definition. This failed, because non-aggregate metrics can only take in other aggregate metrics.

^I think that this behaviour is fine: forcing people to write out metrics instead of doing dimension aggregations in the metric’s sql is pretty acceptable and makes it super clear what the restrictions of these non-aggregate metrics are. It’s also clearly explained in our docs that this is the behaviour to expect.

buuuuuut, it took me like 3 tries to figure out what was going wrong.

This was the yaml I had:

- name: email_campaign_id
        description: The ID of the email campaign.
        tests:
          - unique
          - not_null
        meta:
          metrics:
            campaign_spam_report_rate:
              description: "Spam report rate is the ratio of emails reported as spam out of the emails that were delivered."
              type: number
              sql: "(SUM(${total_unique_spam_reports}) / NULLIF(SUM(${total_unique_deliveries}), 0))"

This was the error I received: Screenshot 2021-08-27 at 10 34 48

This was the fix I needed to make:

- name: total_unique_spam_reports
      meta:
          metrics:
            sum_of_total_unique_spam_reports:
              type: sum

- name: total_unique_deliveries
      meta:
          metrics:
            sum_of_total_unique_deliveries:
              type: sum
  
- name: email_campaign_id
        description: The ID of the email campaign.
        tests:
          - unique
          - not_null
        meta:
          metrics:
            campaign_spam_report_rate:
              description: "Spam report rate is the ratio of emails reported as spam out of the emails that were delivered."
              type: number
              sql: "(${sum_of_total_unique_spam_reports}) / NULLIF(${sum_of_total_unique_deliveries}, 0)"

The error message should have a better description of what’s going wrong. Specifically, it should say something about the metric that’s erroring and the fact that it’s a non-aggregate metric. It should potentially link to the docs if that’s possible too!

e.g.

Error: `campaign_spam_report_rate` is a non-aggregate metric. It can only be defined using aggregate metrics, not dimensions. See the docs for how to build non-aggregate metrics: https://docs.lightdash.com/references/metrics#non-aggregate-metrics

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
owlascommented, Aug 27, 2021

Powerful error message @TuringLovesDeathMetal ! 🚀

0reactions
stale[bot]commented, Jun 25, 2022

Is this issue still relevant? There have been no updates for 60 days, please close the issue or keep the conversation going!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does the "Unable to aggregate ratio metrics" error mean?
This error means you've asked Looker Studio to do something with an already aggregated ratio metric that it can't do. For example, you've...
Read more >
How can I re-categorize any counts < n in Google Data Studio?
1) Issue ... A system error is displayed: Sorry, calculated fields can't mix metrics (aggregated values) and dimensions (non-aggregated values).
Read more >
How do I remove the GROUP BY clause for an explore/view ...
I have a pre-computed metric table that has a small set of dimensions and non-aggregate measures. How do I model this table in...
Read more >
Fixing Tableau Errors: Cannot mix Aggregate and Non ...
In short, the reason for this error is that Tableau cannot mix an aggregate argument e.g. sum(Sales), avg(Profit), Profit Ratio with ...
Read more >
Data Studio Tip: Convert Dimensions to Metrics | Mixed Analytics
Hey Ana, Somehow the GDS isn't allowing me to edit the fields this week, I have worked on this earlier and there was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found