title: Get data from last year
body: <p>I am trying to get data from 1 year ago from the given date in bigquery.
  <code>date(DATE_ADD(date(DATE_ADD(timestamp(New_date),(DATEDIFF(timestamp(New_date), CURRENT_DATE())-1), "DAY")), -354, "DAY"))</code></p>
  
  <p>The query above works, but when I try to put it in a case statement I get null.</p>
  
  <p><code>sum(case when date(New_day) = date(DATE_ADD(date(DATE_ADD(timestamp(New_date),(DATEDIFF(timestamp(New_date), CURRENT_DATE())-1), "DAY")), -354, "DAY")) then 'this is working' else null end) as lastyeardata</code></p>
  
  <p>How do I get data for 1 year ago on the same day to do a YoY comparison?</p>
  
  <p>Edit @Mikhail's suggestions:
  <code>#standardSQl
  WITH `yourTable` AS (
  SELECT 1 AS id, '2017-08-14' AS New_date, '1234' AS volume UNION ALL
  SELECT 2 AS id, '2017-08-13' AS New_date, '2345' AS volume UNION ALL
  SELECT 3 AS id, '2017-08-14' AS New_date, '3456' AS volume UNION ALL
  SELECT 4 AS id, '2017-08-14' AS New_date, '4567' AS volume UNION ALL
  SELECT 5 AS id, '2016-08-14' AS New_date, '5678' AS volume UNION ALL
  SELECT 6 AS id, '2016-08-13' AS New_date, '6789' AS volume UNION ALL
  SELECT 7 AS id, '2016-08-12' AS New_date, '6789' AS volume UNION ALL
  SELECT 8 AS id, '2016-08-11' AS New_date, '1011' AS volume
  )
  select 
    New_date
    ,volume as thisyeardata
    ,Case 
      WHEN PARSE_DATE('%Y-%m-%d', New_date) = DATE_ADD(PARSE_DATE('%Y-%m-%d', New_date), INTERVAL -1 YEAR) 
      THEN volume
    ELSE NULL end as lastyearvolume
    ,DATE_ADD(PARSE_DATE('%Y-%m-%d', New_date), INTERVAL -1 YEAR) as lastyear
  FROM `yourTable`</code></p>
  
  <p>For some reason lastyearvolume is giving me null.  </p>