Previous 4 weeks and next 4 weeks data

Rvannoy
Rvannoy Member
edited March 2023 in Datasets

I want to scheduled a report to go out every Monday. This I know how to do.

I want the report to look at the last/previous 4 weeks and the next 4 weeks. But I want it to do this automatically every week. So every Monday it will look 4 weeks back and 4 weeks forward and the report will send as scheduled.

Is there a way to have the report automatically do this?

Best Answers

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Hi @Rvannoy

    You can't dynamically configure the date selector to go 4 weeks back and 4 weeks forward in the same report. You could configure the card to have a beast mode such that it will compare the date to now - 4 weeks and now + 4 weeks and then return to include it or not.

    CASE WHEN `date_field` = CURRENT_DATE() - INTERVAL '4' WEEK AND `date_field = CURRENT_DATE() + '4' WEEK THEN 'Include' ELSE 'Exclude' END
    

    Then filter your card so that the beast mode is set to 'Include' and schedule your report then. It should take into account any current filtering you have on the card.

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

    @GrantSmith I created the beast mode on the card using the case statement as shown above. replacing 'date_field' with ship_date the formula was accepted.

    (CASE WHEN `Ship_Date` = CURRENT_DATE() - INTERVAL '4' WEEK AND `Ship_Date` = CURRENT_DATE() + INTERVAL '4' WEEK THEN 'INCLUDE' 

     ELSE 'EXCLUDE' END)

    When I use the beast mode in the filter section of the card it only gives me the option for EXCLUDE.

    When the scheduled report goes out on Monday's that is when I need it to look at the 4 previous for 4 weeks and next 4 weeks. When I am just viewing the report on a daily basis I need to be able to just use the date selector to view the dates I select.

  • MarkSnodgrass
    Answer ✓

    You need to change the equals to greater than and equal to and less than and equal to like this:

    (CASE WHEN `Ship_Date` >= CURRENT_DATE() - INTERVAL '4' WEEK AND `Ship_Date` <= CURRENT_DATE() + INTERVAL '4' WEEK THEN 'INCLUDE' 
     ELSE 'EXCLUDE' END)
    
    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Thanks @MarkSnodgrass

    I left out the greater than and less than because it kept auto formatting it as a quote and forgot to put them back in.

    **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 @Rvannoy

    You can't dynamically configure the date selector to go 4 weeks back and 4 weeks forward in the same report. You could configure the card to have a beast mode such that it will compare the date to now - 4 weeks and now + 4 weeks and then return to include it or not.

    CASE WHEN `date_field` = CURRENT_DATE() - INTERVAL '4' WEEK AND `date_field = CURRENT_DATE() + '4' WEEK THEN 'Include' ELSE 'Exclude' END
    

    Then filter your card so that the beast mode is set to 'Include' and schedule your report then. It should take into account any current filtering you have on the card.

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

    @GrantSmith I created the beast mode on the card using the case statement as shown above. replacing 'date_field' with ship_date the formula was accepted.

    (CASE WHEN `Ship_Date` = CURRENT_DATE() - INTERVAL '4' WEEK AND `Ship_Date` = CURRENT_DATE() + INTERVAL '4' WEEK THEN 'INCLUDE' 

     ELSE 'EXCLUDE' END)

    When I use the beast mode in the filter section of the card it only gives me the option for EXCLUDE.

    When the scheduled report goes out on Monday's that is when I need it to look at the 4 previous for 4 weeks and next 4 weeks. When I am just viewing the report on a daily basis I need to be able to just use the date selector to view the dates I select.

  • MarkSnodgrass
    Answer ✓

    You need to change the equals to greater than and equal to and less than and equal to like this:

    (CASE WHEN `Ship_Date` >= CURRENT_DATE() - INTERVAL '4' WEEK AND `Ship_Date` <= CURRENT_DATE() + INTERVAL '4' WEEK THEN 'INCLUDE' 
     ELSE 'EXCLUDE' END)
    
    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Thanks @MarkSnodgrass

    I left out the greater than and less than because it kept auto formatting it as a quote and forgot to put them back in.

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • @GrantSmith Hello, I am trying to look the data just looking at 4 weeks back and then on a sperate card looking 4 weeks forward. When I use the formula

    (CASE WHEN `Ship_Date` >= CURRENT_DATE() - INTERVAL '4' WEEK then 'Include" else 'Exclude')
    
    It is not giving me the data for just the 4 week period.  What am I doing wrong?
    


  • @GrantSmith Sorry, formula is

    CASE WHEN `Ship_Date` >= CURRENT_DATE() - INTERVAL '4' WEEK then 'Include" else 'Exclude' end)
    

    The 4 week backward and 4 week forward formula is working fine. I need to have one that looks at the data for a 4 week backward-looking and a separate on 4 week forward-looking. There is other different criteria depending on how it is viewed. This is why I need to have 2 separate views of the data. I just can not seem to get the beast mode work when I try and just look at the 4 weeks period either going forward or backward.

  • @MarkSnodgrass Hello, I am trying to look my data just 4 week in the past and then in a sperate report 4 weeks looking forward. The 4 week back and 4 week forward is working but when I try and sperate them to just look 4 weeks back and then 4 weeks forward I cannot seem to get it to work.


    CASE WHEN `Ship_Date` >= CURRENT_DATE() - INTERVAL '4' WEEK then 'Include" else 'Exclude' end)
    

    The 4 week backward and 4 week forward formula is working fine. I need to have one that looks at the data for a 4 week backward-looking and a separate on 4 week forward-looking. There is other different criteria depending on how it is viewed. This is why I need to have 2 separate views of the data. I just can not seem to get the beast mode work when I try and just look at the 4 weeks period either going forward or backward.

  • This is how I would write it and then you can filter to whichever result you want in each card.

    CASE WHEN `dt` <= DATE_ADD(CURRENT_DATE(), INTERVAL 4 WEEK) and `dt` >= CURRENT_DATE() then 'Within 4 weeks in the future' 
    WHEN `dt` >= DATE_SUB(CURRENT_DATE(), INTERVAL 4 WEEK) and `dt` <= CURRENT_DATE() then 'Within 4 weeks prior' 
    else 'Outside of 4 weeks past and future' end
    


    Using the date_add function will add 4 weeks to the current date and date_sub will subtract 4 weeks from the current date. I adjust the greater than and less than signs accordingly.

    **Check out my Domo Tips & Tricks Videos

    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.