Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis - Error comparaison two fields

Hi all,

Here's an expression which doesn't work :

COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"},  clientMonthCreationDate= {"=(clientMonthCreationDate >= transactionMonthCreationDate - 2)"}>} distinct transactionId)

I think that the problem comes from this part :

clientMonthCreationDate= {"=(clientMonthCreationDate >= transactionMonthCreationDate - 2)"}

Could you please hep me ?

Best regards,

Simon

1 Solution

Accepted Solutions
swuehl
MVP
MVP

You probably want to select each record where (clientMonthCreationDate >= transactionMonthCreationDate - 2), but you are using it as a search expression on field clientMonthCreationDate. When there are multiple transactionMonthCreationDate per clientMonthCreationDate (which I assume), this logic probably won't return an unambiguous result, right?


If you want to use set analysis, you would need to apply the set modifier for a field that is unique per combination of clientMonthCreationDate and transactionMonthCreationDate, e.g. a primary key for that table.


COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"},  primaryKey = {"=(clientMonthCreationDate >= transactionMonthCreationDate - 2)"}>} distinct transactionId)

Or use an if() statement:

COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"} >} distinct If( (clientMonthCreationDate >= transactionMonthCreationDate - 2), transactionId))


Or try to flag the records that pass your condition in the script, then use set analysis for that flag


COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"},  flag = {1}>} distinct transactionId)

View solution in original post

2 Replies
swuehl
MVP
MVP

You probably want to select each record where (clientMonthCreationDate >= transactionMonthCreationDate - 2), but you are using it as a search expression on field clientMonthCreationDate. When there are multiple transactionMonthCreationDate per clientMonthCreationDate (which I assume), this logic probably won't return an unambiguous result, right?


If you want to use set analysis, you would need to apply the set modifier for a field that is unique per combination of clientMonthCreationDate and transactionMonthCreationDate, e.g. a primary key for that table.


COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"},  primaryKey = {"=(clientMonthCreationDate >= transactionMonthCreationDate - 2)"}>} distinct transactionId)

Or use an if() statement:

COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"} >} distinct If( (clientMonthCreationDate >= transactionMonthCreationDate - 2), transactionId))


Or try to flag the records that pass your condition in the script, then use set analysis for that flag


COUNT({$<clientYearCreationDate= {"$(=YEAR(localtime()))"},  flag = {1}>} distinct transactionId)

Not applicable
Author

Thanks a lot Swuehl, very helpfull !