Filter using two sets of dates

I am currently working on a loss ratio report that aggregates our clients invoice amounts and claim expenditure over a given timeframe.

Here is an example of our claim table and two sample outputs:

The user is required to input both sets of timeframes. As example, a claim may look like this:

Claim Number

Incurred Date

Paid Date

Total Paid

10001

12/25/2020

01/05/2021

$1,000

10000

11/01/2020

11/30/2020

$500

If the user inputs, Incurred Date in 2020 and Paid Dates in 2020 the query should output

Total Paid: $500.

If the user inputs, Incurred Date in 2020 and Paid Dates in 2020 & 2021 the query should output

Total Paid: $1,500.

The explore consists of:

  1. A cross joined table consisting of each client’s group_id and dates from a calendar table
  2. Join Claims table on group_id and incurred date
  3. Join Paid Date Calendar table on the claims.paid_date field. 
  4. Join Invoices on group id and incurred date

Full Explore:

explore: groups_sim {
  from: groups
  label: "Medical Loss Ratio - Claims Test"

  join: incurred_dates {
    from: calendar
    type: cross
    fields: [incurred_dates.date_date, incurred_dates.date_month]
    relationship: one_to_many
  }

  join: claims {
    sql_on: ${groups_sim.pk1_group_id} = ${claims.group_id} and ${incurred_dates.date_date} = ${claims.dos_earliest_date};;
    relationship: one_to_many
  }

  join: paid_date_calendar {
    sql_on: ${claims.paid_date_date} = ${paid_date_calendar.date_date} ;;
    relationship: many_to_one
  }
  
  join: invoices {
    sql_on: ${groups_sim.pk1_group_id} = ${invoices.pk2_group_id} AND ${incurred_dates.date_date} = ${invoices.billing_month_date};;
    relationship: one_to_many
  }
}

Here is an example of the what we would expect to see: 

5e9bc23c-8124-43a0-86f5-fb97341bc35c.png

When I add the paid date filter to the explore, the resulting table filters out Jan & Feb 2020 and filters out Invoice data from Aug and Nov. 

e8e408b0-249b-474b-8d03-c3d9d5c46e74.png

Any help with this will be greatly appreciated. 

0 1 944
1 REPLY 1

The filters work as AND and that’s why you’re not seeing everything. You won’t be able to achieve that kind of conditional logic with normal filters. You may need to use Custom Filters for that..

Top Labels in this Space
Top Solution Authors