Skip to content
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

[SL-1725] [Feature] Reference a measure from another semantic model. #1038

Open
3 tasks done
Jstein77 opened this issue Feb 16, 2024 · 0 comments
Open
3 tasks done

[SL-1725] [Feature] Reference a measure from another semantic model. #1038

Jstein77 opened this issue Feb 16, 2024 · 0 comments
Labels
enhancement New feature or request Medium priority Created by Linear-GitHub Sync Metricflow Created by Linear-GitHub Sync triage Tasks that need to be triaged

Comments

@Jstein77
Copy link
Contributor

Jstein77 commented Feb 16, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing metricflow functionality, rather than a Big Idea better suited to a discussion

Describe the feature

I want to be able to reference a measure in another semantic model at a different entity grain. For example, say I have model called caregiver_visits and another model called visits. visits contains a measure visit_id__scheduled_duration_mins which I want to aggregate at to the caregiver_visits entity. I should be able to express that in the spec. An example of what that might look like is:

semantic_models:
  - name: caregiver_visits
    model: ref('caregiver_visits')
    entities:
      - name: caregiver_visit
        type: primary
        expr: concat( coalesce(caregiver_id, 'no_caregiver_id'), visit_id )
      - name: visit_id
        type: foreign
      - name: branch_id
        type: foreign
        expr: agency_id
      - name: care_recipient
        type: foreign
        expr: care_recipient_id
    dimensions:
      - name: record_updated_at
        type: time
        type_params:
          time_granularity: day
    measures:
      - name: total_scheduled_duration_hours
        label: Visit Duration
        agg: sum
        expr: visit_id__scheduled_duration_mins
        create_metric: true

Querying the total_scheduled_duration_hours metric would resolve to something like the following SQL

select
    total_scheduled_duration_hours
from 
   caregiver_visits
left join (
       select
             concat( coalesce(caregiver_id, 'no_caregiver_id'), visit_id ) as caregiver_visit
           , sum(total_scheduled_duration_hours)
       from 
            visits
       group by 
           1
) as visits_sub_q
ON visits_sub_q.caregiver_visit = caregiver_visits.caregiver_visit

Describe alternatives you've considered

The alternative right now is to create an import CTE in the caregiver_visits model, and reference the measure directly in the caregiver_visits semantic model.

with total_scheduled_duration_hours as (
select
    sum(total_scheduled_duration_hours) as total_scheduled_duration_hours
  , concat( coalesce(caregiver_id, 'no_caregiver_id'), visit_id ) as caregiver_visit
from visits
)

select
* from 
  caregiver_visit cv
left join total_scheduled_duration_hours th on cv.caregiver_vist = th.caregivervist

From SyncLinear.com | SL-1725

@Jstein77 Jstein77 added enhancement New feature or request triage Tasks that need to be triaged labels Feb 16, 2024
@Jstein77 Jstein77 changed the title [Feature] Reference a measure from another semantic model. [SL-1725] [Feature] Reference a measure from another semantic model. Feb 16, 2024
@Jstein77 Jstein77 added Medium priority Created by Linear-GitHub Sync Metricflow Created by Linear-GitHub Sync labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Medium priority Created by Linear-GitHub Sync Metricflow Created by Linear-GitHub Sync triage Tasks that need to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant