Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis, Previous day of selection

Based on my selection of a certain date, I would like my chart to display a sum of a field for that date, and another expression displaying the sum of another field for the day before my current selection.

Exapmle: I select the date 12/3/2010, one expression sums for 12/3/2010 and the other for 12/2/2010

I am using set anlysis which I am new to using. Here is my code that does not work:

sum( {$<Date = {$(#=Only(Date)-1)}>} Sales )

Any help is much appreciated

thanks,

alex

6 Replies
johnw
Champion III
Champion III

You have the right idea.  But when you subtract, it's probably going to replace your date with its numeric equivalent.  I believe the $(#=...) tells it to do the same thing.  Set analysis needs the text version of the date, so you'll need to reformat using date(), get rid of the #, and put it all in single quotes.  Finally, your first $ is optional and I usually omit it to avoid confusion with dollar sign expansion.  So I'm guessing this:

sum({<Date={'$(=date(only(Date)-1))'}>} Sales)

I'd also typically use max() instead of only() so that I get SOME value, even when they haven't selected anything.

Not applicable
Author

I tried this yet I still get no output on my graph. I'm usind the date field as my dimension, could this have something to do with it??

I appreciate your help John.

johnw
Champion III
Champion III

Yes, the date field as a dimension might mess that up.  Assuming only one date is selected, how about removing Date as a dimension, and using only(Date) as an expression?  What sort of chart are you using, and how do you want it to look?

Not applicable
Author

Its a bar chart with 2 expressions (the ones i mentioned in my original post) and the date field as a dimension. All I want is to be able to select a date and have one column show the sum of a field for that date and the other column to show the sum of a field for the day before the date selected.

Not applicable
Author

Can anyone help with this??

Thanks in advance.

rahulgupta
Partner - Creator III
Partner - Creator III

Hey hi,

try using variables: vSelectedDate=date(max(Sampledate))

and use it in the expressions