Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Using Dates in Set Analysis

Hi

I'm trying to do something that I think would be fairly simple, but am failing horribly.

I want to use something like >=2010-01-31 in my date field. I have tried this with formulas and variables, using single and double quotes and equals signs all over the place inside and outside of brackets preceded by $ signs etc. Nothing seems to work.

I have a single dimension called Term, that determines how far back I look (with respect to the current date) in terms of data to include in my sum.

I start with vCurrentDate = Max(Total ReturnDate). I then create vStartDate = MonthEnd($(vCurrentDate),-(Term-1)).

If I then use the following expression: Count({$<ReturnDate={"$(='>='&$(vDate))"}>} ReturnDate), I get the same value for all Terms (where Term = 1,3,6,12,36,60 say).

Where am I going wrong? Is it my date format i.e. YYYY-MM-DD that is creating problems in Set Analysis?

Any help would be appreciated.

Thanks.

Joao.

13 Replies
Anonymous
Not applicable
Author

Here's an image of the result:

Term MonthEnd(Max(TOTAL ReturnDate),-(Term-1)) Count({$<ReturnDate={">="}>} Return)
74
12013-03-3174
32013-01-3174
62012-10-3174
122012-04-3074
362010-04-3074
602008-04-3074
Anonymous
Not applicable
Author

Try this:

   Count({$<ReturnDate={'>=$(vDate)'}>} ReturnDate)

This is a formula that works in my applications:

    sum({$<TransDate={'<=$(BSDurationMEnd)'}>} NLValue)

Make sure the date is  a date though. If you're not sure try creating a second variable that converts it using Date($(vDate)).

Jonathan

shreyashetty_ge
Contributor II
Contributor II

Hi,

Firstly check the date formats whether it is same throughout i.e the variable in which date is stored and the one which you are comparing, in any text object.

Then try this below set analysis .

Count({<ReturnDate={">=$(vDate)"}>} ReturnDate)

Hope it works.

Anonymous
Not applicable
Author

Firstly, apologies for jumping from vStartDate to vDate. They are in fact the same and this is a typo.

Your suggestions don't work. I think the vStartDate is a date because it formats as one if I leave the formatting as expression default. If I change the formatting to Integer, it shows as a number (as per table below). The first column is just Term. The second is vStartDate (shows nothing). The third and fourth are $(vStartDate) formatted differently (third is default, and fourth is integer). The last column is your suggested formula i.e. Count({$<ReturnDate={'>=$(vDate)'}>} ReturnDate)

It has now changed from 72 to 0 (I don't know if that helps).

Thanks again.

Term vStartDate MonthEnd(Max(TOTAL ReturnDate),-(Term-1)) MonthEnd(Max(TOTAL ReturnDate),-(Term-1)) Count
0
12013-03-31413650
32013-01-31413060
62012-10-31412140
122012-04-30410300
362010-04-30402990
602008-04-30395690
Anonymous
Not applicable
Author

Sorry, also does not work. Could I be defining my variables wrongly i.e. do I need '=' in them. Perhaps my definitions above were badly stated, but it does seem to produce the correct dates in theother columns. It is somehow just not doing the set analysis with these dates correctly.

Any other suggestions?

Thanks.

jagan
Luminary Alumni
Luminary Alumni

HI,

Try like this

=Count({<ReturnDate={">=$(=vDate)"}>} ReturnDate)

If you need distinct date then use
=Count({<ReturnDate={">=$(=vDate)"}>} DISTINCT ReturnDate)

Before that check the date formats in date dimension and variable are same.

Hope this helps you.

Regards,

jagan.

Anonymous
Not applicable
Author

Sorry, but still doesn't work.

How do I check date formats in dimension and variable? They are numbers representing dates i.e. get formatted as dates when displayed but internally stored as numbers (see above).

Will it help if i leave out the day i.e. just compare to YYYY-MM?

Thanks.

Joao

Anonymous
Not applicable
Author

How about wrapping a date() function around the vDate ?

   Count({$<ReturnDate={'>=Date($(vDate))'}>} ReturnDate)

Jonathan

Anonymous
Not applicable
Author

I have tried that with no effect.

I can't understand why this is so difficult when it should be so easy. I must be doing something wrong.

Both my ReturnDate and my variables are definitely dates (numbers), not text! Is this the problem?

Thanks.

Joao.