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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
ronp
Contributor
Contributor

Expression to search the same table for a row with specific values

I have a table with the following sample data (first 3 columns) in Qlik Sense.
What expression can give me the 4th column? Basically I am trying to search in the same table for a row with the same User ID as the current row, and a transaction type of 'Sale'.

DateUser IDTransaction TypeDoes this user ID have a sale?
2/15/20213Sale1
2/13/20214Lead0
2/11/20215Sale1
1/20/20213Lead1
1/18/20215Lead1

 

Thanks in advance, I can't work this one out!

5 Replies
lironbaram
Partner - Master III
Partner - Master III

Hi, 
this expression should work for you 

count(aggr(if(MaxString(total<[User ID]>[Transaction Type])='Sale' , Date ),Date,[User ID]))
ronp
Contributor
Contributor
Author

Hello - thanks for your help.
This doesn't appear to be working for me. Returns 0 for all rows.

If i try to break it down and make a measure with only this part:
MaxString(total<[User ID]>[Transaction Type])
Then it always returns 'Lead' for every row

By the way, for my real data the expression looks like this:
count(aggr(if(MaxString(total<user_id>type)='subscription' , [billing_changes.created_at] ),[billing_changes.created_at],user_id))

How can I figure out what i'm doing wrong? Have been messing with this one for a few days hehe

lironbaram
Partner - Master III
Partner - Master III

the strange thing is this part 
MaxString(total<[User ID]>[Transaction Type]), should return subscription as s is coming after l can you check if you have some leading spaces or something 

ronp
Contributor
Contributor
Author

For my real data it's 'trial' and 'subscription'.
There are also other types as well.. sorry I didn't know it would affect the formula!

stevejoyce
Specialist II
Specialist II

Surely you values will matter for an expression to work.  I would recommend a slightly different calculation that eliminates the if-statement and string-comparison, instead using set anlaysis.

sum(total <[User ID]> aggr(Count(distinct{<[Transaction Type] = {'Sale'}>} 1), [User ID]))