# Multiplying or Dividing Dimensions and Measures in the Data Model Using \`in\_query\`

**URL:** <https://community.omni.co/t/multiplying-or-dividing-dimensions-and-measures-in-the-data-model-using-in-query/207>\
**Category:** Modeling\
**Created:** [January 2, 2025, 11:33pm UTC](https://community.omni.co/t/multiplying-or-dividing-dimensions-and-measures-in-the-data-model-using-in-query/207 "2025-01-02T23:33:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/colin/32/112_2.png) [@colin](https://community.omni.co/u/colin)\
**Post date:** [January 2, 2025, 11:33pm UTC](https://community.omni.co/t/multiplying-or-dividing-dimensions-and-measures-in-the-data-model-using-in-query/207/1 "2025-01-02T23:33:47Z")

</div>

In most SQL dialects, one can only do math between dimensions (things in the group by) and measures (aggregates, not in the group by) when said dimensions are in the query.

Omni restricts these query-structure contingent fields in the data model by default, but they can be built using `in_query` to model around corner cases.

Here’s a quick example that is not allowed

```auto
  sale_price_per_year_of_life:
    sql: ${order_items.sale_price_sum}/${users.age}

```

Note how we are mixing measures (`order_items.sale_price_sum`) and dimensions (`users.age`). This will only work is users.age is in the query and thus is blocked by default. To support we simply lean on `in_query`:

```auto
 max_age:
    sql: ${users.age}
    aggregate_type: max
    description: dummy aggregate for sale_price_per_year_of_life

  sale_price_per_year_of_life:
    sql: CASE WHEN {{ users.age.in_query }} THEN
      ${order_items.sale_price_sum}/${users.max_age} ELSE 'Add users.age to compute'
      END

```

Note that we have replaced the dimension with an aggregate (`users.max_age`), but the aggregation will only be computed with `users.age` is in the query - otherwise we’ll provide a warning to the user.

Here is the result:

 ![Screenshot 2025-01-02 at 3.33.32 PM](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/00f3982f9f9ec33d037e0ddc109ffed4d9b6b36c.png)  
 ![Screenshot 2025-01-02 at 3.33.19 PM](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/0e9a0c40bd21a72ccb464d7d8ba0f8d721adc8df.png)
