svetla87
New Contributor II

Hello @SteveOstrowski 
Having a table cards_daily_snapshot with columns time_key, month_id, account_id, card_id, credit_limit, account_status. Need to create a metric for total credit limit, by getting the max value of it per account_id and snapshot date (time_key). It should achieve similar result as in the query with a metric view.


with cte as (
    select time_key,month_id,account_id,max(credit_limit) as credit_limit
from demo_cat.demo.cards_daily_snapshot
    where 1=1
    and account_status='A'
    group by 1,2,3  
)
select month_id, sum(credit_limit) as credit_limit from cte group by 1 order by 1;

I'm trying with a window measure which gets the credit_limit on account level, and then another measure which aggregates it across the data set. Getting an error during querying the aggregating measure
select  month_id,measure(credit_limit_agg) as lmt from demo_cat.demo.credit_card_metric_view
group by month_id;

[METRIC_VIEW_WINDOW_MEASURE_REFERENCES_WINDOW_MEASURE] Window measure `credit_limit_agg` cannot reference another window measure `account_credit_limit`. SQLSTATE: 0A000

My Yaml looks something like below:
 

measures:
- name: account_credit_limit
expr: MAX(credit_limit) FILTER(WHERE derived_account_status='A')
window:
- order: account_id
semiadditive: last
range: cumulative
- order: time_key
semiadditive: last
range: cumulative
display_name: Account Credit Limit
- name: credit_limit_agg
expr: sum(MEASURE(account_credit_limit)) over()
display_name: Total Credit Limit