Join tables

To get the sum of sales for a specific date and how it was a year ago on the same date, I join the table like this.

explore: store_sales {
from: store_sales
label: “Store Sales”
join: store_sales_ly {
from: store_sales
relationship: one_to_one
type: left_outer
sql_on: ${store_sales.store_id} = ${store_sales_ly.store_id}
AND ${store_sales.business_week_of_year} = ${store_sales_ly.business_week_of_year}
AND ${store_sales.business_day_of_week_index} = ${store_sales_ly.business_day_of_week_index}
AND ${store_sales.business_year}-1 = ${store_sales_ly.business_year}

This means that I get 2 dimensions. One with today’s date and sales and one with LY_date and LY_sales exactly one year ago.

This takes a very long time and I wonder if anyone has any idea how to improve the time

Hey Steven - check out this block of code. This is how I’ve implemented it and it’s been great! Date Comparison Block

1 Like

Thank you!

I tested it but the numbers are wrong in the results and I dont understand why.