I need to sum the latest month's and the previous month's traffic for each Name. I'm trying with beast mode.
My data is like so:
Name Date Traffic (desc)
AAAA 2018/10/31 2,358,817
AAAA 2018/11/06 2,483,452
BBBB 2018/10/30 2,555,555
BBBB 2018/11/06 2,123,123
As the 'day' part varies from month to month I tried cutting off the day with DATE_FORMAT() for latest month.
case when DATE_FORMAT(`Date`, '%Y-%m') = max(DATE_FORMAT(`Date`, '%Y-%m')) then `Traffic (desc)` end
But I cannot get the calculation for the previous month to work. I get a blank with the following.
case when DATE_FORMAT(`Date`, '%Y-%m') = DATE_SUB(max(DATE_FORMAT(`Date`, '%Y-%m')), interval 1 month) then `Traffic (desc)` end
I also get a blank with MONTH().
case when MONTH(`Date`) = DATE_SUB(MONTH(MAX(`Date`)), interval 1 month) then `Traffic (desc)` end
I'm not sure what is wrong here.
Can somebody help me?