Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
See why BI users voted Qlik #1 in 11 categories. GET REPORT
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor II
Contributor II

How to use a Set Analysis result as the n-value of AddYears function

I want to use the AddYears function in a dimension (column of a table), but not with a static n-value that indicate the years to add or subtract.

One of the Columns indicate the Depreciation Year. In order to indicate the depreciation years I had to do the following: AGGR(ONLY ({<[Attribute Code]={'DEPRECIATION YEARS'}>} [Attribute Value]),[Asset Code]))  this provides a number, e.g. 4

I now what to use that value in another column to indicate the Remaining Depreciation Year. I wanted to do the following: AddYears([Commissioned On Date] , AGGR(ONLY ({<[Attribute Code]={'DEPRECIATION YEARS'}>} [Attribute Value]),[Asset Code])) . This does however not work. 

When I do the following:  AddYears([Commissioned On Date] , 4) I get the answer I am looking for, but the n-value of the AddYears value will be dynamic for each Asset that is in the table.

Thanks is advance

Marisa

Labels (1)
1 Solution

Accepted Solutions
Highlighted
Specialist II
Specialist II

Hi 

What about creating a variable with you mesure to calculate the depreciate year 

And then use this variable in your addyear mesure 

variable : 

vDepreciate_Year = AGGR(ONLY ({<[Attribute Code]={'DEPRECIATION YEARS'}>} [Attribute Value]),[Asset Code]))

 

mesure : 

AddYears([Commissioned On Date] ,$(vDepreciate_Year ) )

 

Hope it helps 

View solution in original post

3 Replies
Highlighted
Specialist II
Specialist II

Hi 

What about creating a variable with you mesure to calculate the depreciate year 

And then use this variable in your addyear mesure 

variable : 

vDepreciate_Year = AGGR(ONLY ({<[Attribute Code]={'DEPRECIATION YEARS'}>} [Attribute Value]),[Asset Code]))

 

mesure : 

AddYears([Commissioned On Date] ,$(vDepreciate_Year ) )

 

Hope it helps 

View solution in original post

Highlighted
Contributor II
Contributor II

Thanks for the reply.

I have tried that now, but I am still not getting an answer. 

Highlighted
Contributor II
Contributor II

Thank you so much. At first it did not work, but that was because the Depreciate_Year was seen as text and not a number. I just added num# in front of it and it work.

Thanks again

Marisa