YOY in table card beast mode

How can i display YOY Sales Data side by side in table card using beast mode. I am using this beast mode to display LY

 

Case when year(DATE_SUB(CURDATE(), interval 1 year)) = year(`Date`) then `Net Sales` end and date selected in table card is This Month

Comments

  • n8isjack
    n8isjack Contributor

    Your Beastmode looks good, but you can't use the card's date selection because it is year specific. In essence when you choose 'This Month' then you filter out all data from last year.

     

    Consider these beastmodes with no date filter:

     

     

    `This Year`
    CASE
    WHEN YEAR(CURRENT_DATE()) = YEAR(`Date`)
    THEN `Net Sales`
    END

    `Last Year`
    CASE
    WHEN YEAR(CURRENT_DATE()) - 1 = YEAR(`Date`)
    THEN `Net Sales`
    END

    `Month` (for filtering)
    CASE
    WHEN MONTH(CURRENT_DATE()) = MONTH(`Date`)
    THEN 'This Month'
    ELSE 'Other'
    END

     

    Then add a FILTER using the new beastmode `Month` and filter to 'This Month' which is not year specific.

     


    **Say "Thanks" by clicking the "heart" in the post that helped you.
    **Please mark the post that solves your problem by clicking on "Accept as Solution"
  • pauljames
    pauljames Contributor

    @n8isjack when i take the difference between this year and last year, i'm not getting YoY returned…

    IF I SOLVED YOUR PROBLEM, PLEASE "ACCEPT" MY ANSWER AS A SOLUTION. THANK YOU! 😎😎😎

  • n8isjack
    n8isjack Contributor

    @pauljames there are a lot of simple reasons that get in the way. Without more detail it is hard to say why that might be in your case.

    First, the above formula lets you see them side by side, but to compare them it would have to be aggregated. The same record cannot be both this year and last year, but if you use a SUM to aggregate the rows it could compare the two.

    -- `This Year`
    SUM(CASE
    WHEN YEAR(CURRENT_DATE()) = YEAR(`Date`)
    THEN `Net Sales`
    END
    ) -

    `Last Year`
    SUM(CASE
    WHEN YEAR(CURRENT_DATE()) - 1 = YEAR(`Date`)
    THEN `Net Sales`
    END
    )

    Even that leaves lots of 'gotcha' concerns. The biggest one is grouping. Aggregate grouping is automatically affected by the card settings. In a table view all "non-aggregated" columns will form the group basis. So if you show Year(`Date`) as a column then each row can only use data from a single year. Nullifying the effect of the logic shown above.

    This is hidden further in any other chart type. If you have a date grain on a bar chart for example, this will never work because a record from last year and a record from this year won't exist in the same date grain. Thus prohibiting the beast mode (which gets the data last after filters and grouping) from ever seeing records from both years to do math with them.


    **Say "Thanks" by clicking the "heart" in the post that helped you.
    **Please mark the post that solves your problem by clicking on "Accept as Solution"