Skip to content

How to query for total number of inquiries by status (at the given time)? #9552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ivan-wolf opened this issue May 7, 2025 · 0 comments
Open
Labels
question The issue is a question. Please use Stack Overflow for questions.

Comments

@ivan-wolf
Copy link

Problem

We're developing a system in which users submit inquiries (tickets, issues), for which the status is tracked (so very much like GitHub issues).
We store the following in the database:

  • Inquiries
  • Status changes for each inquiry

Now, the idea is to present a graph in the user interface which shows how many inquiries there were in system for each status at a specific time. Here's an example:

Image

For this purpose, we built a table with a snapshot for each day (which represents the finest granularity that is required) and inquiry, which is exposed as cube inquiry_snapshots.

day inquiry status
2025-01-01 1 open
2025-01-01 2 open
2025-01-02 1 open
2025-01-02 2 resolved

With the following query, the results are as expected:

{
  "measures": [
    "inquiry_snapshots.count"
  ],
  "dimensions": [
    "inquiry_snapshots.status"
  ],
  "timeDimensions": [
    {
      "dimension": "inquiry_snapshots.day",
      "dateRange": [
        "2025-01-01",
        "2025-01-31"
      ],
      "granularity": "day"
    }
  ]
}

Our problem is how to accomplish the same with higher granularities (week, month, etc.), as now the inquiry could've been in more than one status over the span of each time frame (as seen in the above example: inquiry 2), but only the last status (in each time frame) is relevant.

Related schema

cubes:
  - name: inquiry_snapshots
    sql_table: inquiry_snapshots

    dimensions:
      - name: day
        sql: day
        type: time
        primary_key: true

      - name: inquiry
        sql: inquiry
        type: string
        primary_key: true

      - name: status
        sql: status
        type: string

    measures:
      - name: count
        sql: inquiry
        type: count_distinct

Practical example

Granularity day ✅:
Image

Granularity week ❌:
Image

As we can see, in week 10 there were many status changes (to resolved), which causes inflated numbers, because a single inquiry is counted more than once (i.e. once for each status it was in during the given week).

Did someone face a similar challenge and could point us in the right direction about how to model this? Any help would be much appreciated!

@ivan-wolf ivan-wolf added the question The issue is a question. Please use Stack Overflow for questions. label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a question. Please use Stack Overflow for questions.
Projects
None yet
Development

No branches or pull requests

1 participant