Qlik Community

Ask a Question

App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Support Cases coming to Qlik Community Oct. 4! Start chats, open cases, explore resources: READ DETAILS
Showing results for 
Search instead for 
Did you mean: 
Contributor III
Contributor III

Parameter with function (YearStart) inside a variable

I want to use a function fYTD, that I succeeded to make with the following code :

Set vMaxDate='30/12/2019';
Let vDateDeb=YearStart('$(vMaxDate)');
Set fYTD='YTD' & ' ' & (count({$<Date= {">=$(vDateDeb)<=$(vMaxDate)"}, $1>} $2));


Now instead of having the DateDeb variable, I would like to have a third parameter inside fYTD (YearStart('$(vMaxDate)');) ?

Something that I would use like that:

$(fYTD($(vMaxDate),[Contrat_type]={'Coll'},NUM_SO ))


Tried many things but it never work... Any idea ?

I don't get any date in the final result.

Labels (2)
1 Reply
MVP & Luminary
MVP & Luminary

Your dates seems to be quite static - therefore why do you want to add them within the call? I think I would rather do it in this way:

Let vMaxDate = num(makedate(2019, 12, 30));
Set fYTD = 'YTD ' & (count({$<DateNum = {">=floor(yearstart($(vMaxDate)))<=$(vMaxDate)"}, $1>} $2));

and then calling it with: $(fYTD([Contrat_type]={'Coll'},NUM_SO ))

The use of num(), floor() and DateNum isn't accidentally else it avoids the quite common issues that the variables have the wrong format, are not interpreted as dates or are interpreted as divisions like 30/12/2019 or aren't dates else timestamps like yearstart() would return. Of course everything of it could be done additionally within the variables/calls - but why doing simple things in a complicated way?

Even more likely as the above would be that I would flag YTD and similar things within the master-calendar and then the variable and call might look like:

Set fYTD = '$1 ' & (count({$<[$1] = {1}, $2>} $3));

$(fYTD(YTD,[Contrat_type]={'Coll'},NUM_SO ))

- Marcus