Help With Templated Filter and Liquid

Hi All,

I’m trying to create a derived table that lets me input a date and pull value from 7 days prior to that date. I think I’m supposed to be using templated filters and liquid. This is my model

view: 7_days_ago_daily_charges_with_exclusions {

derived_table: {
  sql: SELECT DATE(bc.`date`) AS Date,
    SUM(bc.`amount`) AS Charges
    FROM businesses b
    JOIN billing_charges bc ON bc.`client_id` = b.`id`
    LEFT JOIN apps_partners ap ON ap.`id` = b.`appsPartner_id`
    WHERE (ap.`id` IS NULL OR (ap.`id` != 155 AND ap.`id` != 187))
    and date_add({% condition Date %} Date {% endcondition %}, interval -7 day)
    GROUP BY DATE(bc.`date`)
     ;;
}

dimension: Date {
  type: date
  sql: ${TABLE}.Date;;
  primary_key: yes
}

dimension: Charges {
  type: number
  sql: ${TABLE}.charges ;;
}

But im getting no results because of this sql being generated:

and date_add(((( Date ) >= ((TIMESTAMP(‘2020-03-17’))) AND ( Date ) < ((DATE_ADD(TIMESTAMP(‘2020-03-17’),INTERVAL 1 day))))), interval -7 day)
GROUP BY DATE(bc.date)

0 1 206
1 REPLY 1

What is the error? At first glance I could possible see an issue comparing DATE and TIMESTAMP. I’ve been working a lot with time comparisons lately and I got that error many times

Top Labels in this Space
Top Solution Authors