I am trying to create a table that has a column that shows a total from the previous week and a column with a total from 2 weeks prior. The data crosses the new year, 2020 to 2021. When I create the calculation for 2 weeks prior, it yields an accurate result but when I try a similar calculation for the previous week, it is not accurate.
Here is the calculation I am using for the sum of visit 2 weeks prior:
Sum(CASE WHEN WEEK(DATE_SUB(Current_Date(), INTERVAL 2 WEEK)) = WEEK(`Visit Start Date`) AND YEAR(DATE_SUB(Current_Date(), INTERVAL 2 WEEK)) = YEAR(`Visit Start Date`) THEN 1 Else 0 End)
I tried to get the total for the previous week using the calculation below and it is not yielding the correct results.
Sum(CASE WHEN WEEK(DATE_SUB(Current_Date(), INTERVAL 1 WEEK)) = WEEK(`Visit Start Date`) AND YEAR(DATE_SUB(Current_Date(), INTERVAL 1 WEEK)) = YEAR(`Visit Start Date`) THEN 1 Else 0 End)
What calculations would be best for this scenario?