Can I calculate a dimension in one view that references a derived table from another view?

I currently have two views: View A has a list of customers and View B has a list of orders. The two views are linked in a model on a customer ID field. I want to create a yesno field on View A that would denote if a customer has had at least x amount of orders in the last y months. My first attempt at doing this was to create a dimension on View A that references View B and tries to count the number of orders, and then I was going to use that count to create the yesno dimension. Here’s the code I was using in View A to try to do that:

dimension: total_orders {
type: number
sql:
(
select count(distinct o.order_id)
from ${orders.SQL_TABLE_NAME} as o
where o.customer_id = ${TABLE}.customer_id
) ;;

What I’m trying to figure out is: (1) Is what I’m trying to do possible? and (2) If it is, am I going about it the right way?

Any help is appreciated. Thanks

0 0 147
0 REPLIES 0
Top Labels in this Space
Top Solution Authors