Skip to main content
Question

Dynamically set starting date of a chart

  • December 15, 2025
  • 5 replies
  • 36 views

Hello,

I have a dataset with a “date” variable and I would like to dynamically assign the start date of my graph as the last date in my dataset -20 years. I can use an ods-adv-analysis to obtain the latest date in my dataset, but I can't subtract 20 years from it. Furthermore, I can hardcode the start date, but not using a dynamic variable:

<div
ods-adv-analysis="maxdate"
ods-adv-analysis-context="pibcroissancetrimestre"
ods-adv-analysis-select="max(date) as maxdate"
>
{{last_date = maxdate[0].maxdate; ""}}
{{last_date}}
{{
pibcroissancetrimestre.parameters['q.from_date.date'] =
'date>=2005-09-30T00:00:00+00:00 ';
""}}

Can someone help me fix this code?

Thanks in advance

Nathan

5 replies

Thomas R.
Huwise Team
  • Huwise Team
  • December 15, 2025

Hello Nathan,

You can easily do this with a filter it would look something like this : 

{{ twentyYearsAgoFromLatestDate = (latestDateFromDataset | momentadd:'years':-20) ; "" }}

Regarding the configuration of the start date, could you share the code you’re using it to set it dynamically?

Best,

Thomas

 


Hello Thomas,

Thank you for your answer. I try to do it this way:

<div  
ods-adv-analysis="maxdate"
ods-adv-analysis-context="pibcroissancetrimestre"
ods-adv-analysis-select="max(date) as maxdate">

{{ twentyYearsAgoFromLatestDate = (maxdate[0].maxdate | momentadd:'years':-20) ; "" }}

{{pibcroissancetrimestre.parameters['q.from_date.date'] ='date>=twentyYearsAgoFromLatestDate ';""}}

But it obviously doesn’t work. I don’t know how to fill the variable twentyYearsAgoFromLatestDate in {{pibcroissancetrimestre.parameters['q.from_date.date'] ='date>=';""}}

Can you help me do this?

Thanks a lot,

Nathan


Thomas R.
Huwise Team
  • Huwise Team
  • December 15, 2025

Nathan,

The way you are using the variable on the example you gave is as a string, everything between the single quotes are considered as literal text.

Thus if you want to mix text and a value from a variable you’ll need to concatenate the two.

Here is your example corrected.

{{pibcroissancetrimestre.parameters['q.from_date.date'] ='date>=' + twentyYearsAgoFromLatestDate ;""}}

Best regards,

Thomas.


I had already tried to do that, but unfortunately it doesn't work. It tells me “no data available yet.” However, when I type

{{twentyYearsAgoFromLatestDate}}

to debug, I see 2005-09-30T00:00:00Z appear, and if I do

{ {pibcroissancetrimestre.parameters[‘q.from_date.date’] =‘date>=’ + ‘2005-09-30T00:00:00Z’;“”}}

 it works.

Do you know what the problem is here?


Thomas R.
Huwise Team
  • Huwise Team
  • December 18, 2025

Hello Nathan,

Your best bet would be to support@huwise.com with information about the dataset, portal and ideally the full code, also link this thread.

Best regards,

Thomas