Custom Measure for finding value for today and yesterday

I am needing to show the number for today and yesterday for a specific dimension. I have a measure already for current day value I am trying to get the value for “yesterday” but I cannot do what I thought would work: 

add_days(-1,now( )) but this is an causing an issue. 

0 1 7,856
1 REPLY 1

Hi @brittany_juarez

I can suggest 3 ways to approach this:

  1. Filtered measure:
    •  This is my preferred solution as it would allow you to reutilize the measures in the explore.
         measure: sum_dimension_today {
      type: sum
      sql: ${my_dimension};;
      filters: [date: "today"]
      }

      measure: sum_dimension_yesterday {
      type: sum
      sql: ${my_dimension};;
      filters: [date: "yesterday"]
      }
  2. Filter or Custom filter:
    • You can use the filter functionality directly OR create custom filters. Depending on your use case, you could adjust this: 
      matches_filter(${dates.day_date}, `today`)
      OR
      matches_filter(${dates.day_date}, `yesterday`)
  3. Your code revised: 
    • Using now() will return a timestamp, if you want to reference a full day, you need to truncate it. Try this:
      add_days(-1,trunc_days(now( ))) 

Hope this helps you!

Top Labels in this Space