Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Denzyl
Contributor II
Contributor II

Sum expression where a date column matches a date variable

I created a variable vLatestDate which is derived from the max month of the [date] column

Denzyl_0-1661777856696.png

vLatestDate:

=Max([date])

 I am now trying to create a column that is a sum expression based on the [date] column matching the vLatestDate variable.

I have tried the follow, but it did not work:

SUM({<[date]=vLatestDate>} [amount])

However, the following code does:

SUM(IF([date]=vLatestDate, [amount])

Why does the first code not work while the second does?

Labels (1)
1 Solution

Accepted Solutions
Or
MVP
MVP

You seem to have left out the $() required to parse the variable.

Try instead:

SUM({<[date]=$(vLatestDate)>} [amount])

or

SUM({<[date]= {'$(vLatestDate)'} >} [amount])

 

View solution in original post

4 Replies
Or
MVP
MVP

You seem to have left out the $() required to parse the variable.

Try instead:

SUM({<[date]=$(vLatestDate)>} [amount])

or

SUM({<[date]= {'$(vLatestDate)'} >} [amount])

 

Denzyl
Contributor II
Contributor II
Author

The following code worked:

SUM({<[date]= {'$(vLatestDate)'}>} [amount])
Denzyl
Contributor II
Contributor II
Author

Would it be possible to get the [amount] where [date] = vLatestDate - 1 month?

I have tried the following codes but it doesn't work:

SUM({<[date]= {'$(addmonths(vLatestDate, -1))'}>} [amount]) 

 and

SUM({<[date]= {$(addmonths(vLatestDate, -1))}>} [amount]) 

the expression shows blank values:

Denzyl_0-1661844344523.png

 

Or
MVP
MVP

Have a look at e.g. this thread for examples of using an expression in the set analysis comparison.

https://community.qlik.com/t5/QlikView-App-Dev/Using-an-expression-within-Set-Analysis/m-p/910261