Is there any way of setting a dynamic default value?

I've been trying to use a dynamic default value, as in this case for setting the default date to the current date, but I don't manage to get it to work...

SELECT CURRENT_DATE() AS current_date

{% form %}

start_date:
  type: date
  default: 2017-10-01

end_date:
  type: date
  default: current_date

{% endform %}

I know there is a tutorial on that you can make the type to text and use "today" and some if-clauses etc., but I'm not interested in that, I want the type to be date.

Is this possible in any way?

4replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Andreas ,

    If you don't include a default, the date parameter should use today's date in the report UI.  If you're looking to set a default date value to run in the query editor, you an use syntax like this.  This example gives you the date 7 days ago:

    {% form %}
    date:
      type: date
      default: {{'now' | date: "%Y"}}-{{'now' | date: "%m"}}-{{'now' | date: "%d" | minus: 7}}
    
    {% endform %}
    Reply Like 1
  • Hello Donna McGahan 

    The syntax you posted worked really good! Thanks!

    Reply Like
  • Hello again Donna McGahan!

    This doesn't work when the month is January. Doing this:

    default: {{'now' | date: "%Y"}}-{{'now' | date: "%m" | minus: 1}}-{{'now' | date: "%d"}}

    Will result in the following:

    2018-0-02

    Reply Like
  • Hi Andreas Rolén - sorry for the delayed response. A different approach may solve for this case:

    date_param:
      type: date
      default: {{ 'now' | date: '%s' | minus: 604800 | date: '%Y-%m-%d' }}
    

    There are also more examples of using Liquid to create a calculated date in our documentation:

    https://help.modeanalytics.com/articles/parameters/#default-to-a-calculated-date

    Hope that helps - please do reach out to our success team via in-product chat or success@modeanalytics.com if we can be of further assistance. Thanks!

    Reply Like
Like Follow
  • Status Answered
  • 9 mths agoLast active
  • 4Replies
  • 848Views
  • 3 Following

Create A New Discussion

Share your thoughts