Qlik Community

Ask a Question

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

cancel
Showing results for 
Search instead for 
Did you mean: 
AgataKK
Contributor II
Contributor II

AddMonths for multiple values

Hello!

I have a statement: 

=Date(AddMonths(Date#((GetFieldSelections([Rok-Miesiąc], ', ', 99)), 'YY-MM'), -12), 'YY-MM')

and it works if the end user picks only one date - e. g. if he picked 19-06 it prints out the 18-06 value.

If he picks two or more dates it doesn't work, but the statement without AddMonths works perfectly - it prints all the values the user picked.

Why the AddMonths works only for one value? How can I change the statement to make it work?

I tried to use Concat, but it still doesn't work.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

ConcatDistinct Date(AddMonths(Date#([Rok-Miesiąc], 'YY-MM'), -12), 'YY-MM'), ',')

View solution in original post

4 Replies
tresesco
MVP
MVP

The expression you are using is potentially wrong. Where are you using this expression, in a chart, or textbox? Try to share a sample app explaining your expected output with context.

AgataKK
Contributor II
Contributor II
Author

I have a defined calendar loaded by a script, the end user can pick dates (YY-MM) from the list.

I use this expression in a textbox and I expect that the expression will print picked dates but from previous year, so:

1) the end user picks 19-06, 19-05 and 19-01.

2) the textbox shows 18-06, 18-05, 18-01.

 

tresesco
MVP
MVP

Try like:

ConcatDistinct Date(AddMonths(Date#([Rok-Miesiąc], 'YY-MM'), -12), 'YY-MM'), ',')

View solution in original post

AgataKK
Contributor II
Contributor II
Author

It works, thank you!

I also added IF(GetSelectedCount([Rok-Miesiąc])<>0   at the beginning to make it work only after picking dates 🙂