How to create a card with data from the calendar month before last

Hi, does anyone have any thoughts on how to create a card that contains rolling data for a calendar month that was 2 months ago?

Example 1, If today's date is June 15th, card should show data for the whole month of April

Example 2, If today's date is November 30th, card should show data for the whole month of September

Thanks all

Tagged:

Best Answer

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Hi @richardjmarshall

    You've got two options.

    1) You could use a beast mode to determine if a date is from 2 months ago

    CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN 1 ELSE 0 END
    

    and then just filter on that value being 1.

    This method you're always stuck looking at 2 months ago according to the current month. The next option is better in that it will allow you to look at 2 months ago based on any date you have selected in your chart.


    2) The more robust option would be to create a custom date dimension table where you have customized offsets (With a report date and a comparison date). You'd then use a Fusion / View to join that dataset to your main dataset based on your date field and the comparison date field. You then can filter for your offset type of 2 months ago. This has been outlined several times here on the dojo. See https://dojo.domo.com/t5/Card-Building/show-percent-on-period-over-period-graph/m-p/50540/highlight/true#M7313.

    I highly recommend method 2 as it gives you much more flexibility when processing and displaying your data.


    Also @jaeW_at_Onyx has a nice video he put out which outlines this process as well:

    https://www.youtube.com/watch?v=CDKNOmKClms

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**

Answers

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Hi @richardjmarshall

    You've got two options.

    1) You could use a beast mode to determine if a date is from 2 months ago

    CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN 1 ELSE 0 END
    

    and then just filter on that value being 1.

    This method you're always stuck looking at 2 months ago according to the current month. The next option is better in that it will allow you to look at 2 months ago based on any date you have selected in your chart.


    2) The more robust option would be to create a custom date dimension table where you have customized offsets (With a report date and a comparison date). You'd then use a Fusion / View to join that dataset to your main dataset based on your date field and the comparison date field. You then can filter for your offset type of 2 months ago. This has been outlined several times here on the dojo. See https://dojo.domo.com/t5/Card-Building/show-percent-on-period-over-period-graph/m-p/50540/highlight/true#M7313.

    I highly recommend method 2 as it gives you much more flexibility when processing and displaying your data.


    Also @jaeW_at_Onyx has a nice video he put out which outlines this process as well:

    https://www.youtube.com/watch?v=CDKNOmKClms

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • Hi @GrantSmith - method 1 works perfectly and has now been rolled out to a suite of cards. For this purpose, being 'stuck' working from the current date is ok, the cards are being used to schedule a monthly export of raw data to a third party.

    Method 2 is excellent for not relying on reference to the current date and I will no doubt use it in the future for another card.

    Thanks for your help!

  • ST_Superman
    ST_Superman Domo Employee

    @richardjmarshall One piece of advise that I would offer. And this is just to provide some more clarity and flexibility to the field that you are filtering on. I would recommend not just using 'THEN 1 ELSE 0'

    CASE 
      WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) 
        THEN '2 Months Ago'
      ELSE 'Other'
    END
    

    Using something like this makes it more intuitive for anyone else using this filter to understand what they are filtering for. In addition, you could add more options:

    CASE 
      WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) 
        THEN '2 Months Ago'
      WHEN LAST_DAY(CURDATE() - INTERVAL '1' MONTH) = LAST_DAY(`Date Field`)
        THEN '1 Month Ago'
      ... etc.
      ELSE 'Other'
    END
    

    Users could then use this field to dynamically set a default view for any number of months they wanted the card to look back to.