Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sagarjagga
Creator
Creator

Difficulty in finding out count using aggr()

Hi All,

I need to count username based on latest rating in selected date range.Below is the sample data.

User NameRatingupdate date
A110/11/2018
b110/15/2018
c211/1/2018
d011/1/2018
A211/5/2018
c311/6/2018

 

i need to count user name against the latest ratings where update date less than [selected date] . for example if selected will be 11/6/2018 and username will be A then final output will look like.

 

Ratingcount of user name
10
2

1

3

0

 

as for user name A and as of selected date 11/6/2018 we have latest rating 2 (on update date 11/2/2018)

 

if we select a date as 11/4/2018 the final output will look like

Ratingcount of user name
12  (as A,B)
2

1 (as c)

3

0

rating 1 has 2 count as both A and B username has latest rating 1 on update date 10/11 and 10/15 respectively as of selected date 11/4/2018. 

 

Note - selected date field is a field which i am pulling from date table which contains all calendar date. the use of selected date field is just to select a range of update dates upto selected date

for instance - {<[update date]={"=${<=max([selected date])}"}>}

 

regards

1 Solution

Accepted Solutions
sunny_talwar

In that case try this

=Aggr(
FirstSortedValue({<[update date] = {"$(='<=' & Max([update date]))"}>}Rating, -([update date] + (Rating/1E10)))
, [User Name])

View solution in original post

6 Replies
sunny_talwar

Try this

Dimension

 

=Aggr(FirstSortedValue({<[update date] = {"$(='<=' & Max([update date]))"}>}Rating, -[update date]), [User Name])

Expression

 

=Count(DISTINCT {<[update date] = {"$(='<=' & Max([update date]))"}>} [User Name])
sagarjagga
Creator
Creator
Author

Thank so much sunny. The above solution is working fine if i have distinct update date against usernames but if i have same update date against a particular username then it is giving null rating against same user name. for example if my sample data is like
Thank so much sunny. The above solution is working fine if i have distinct update date against usernames but if i have same update date against a particular username then it is giving null rating against same user name. for example if my sample data is like

User NameRatingupdate date
A110/11/2018
A310/11/2018
b110/15/2018
c211/1/2018
d011/1/2018
A211/5/2018
c311/6/2018

 

 

if we select a date as 11/4/2018 the final output will look like

Ratingcount of user name
11 (B)
2

1 (as c)

3

0

NULL

1(A)

 

it is counting A username in null as A has same update date in the selected range. is there any way to handle that.

 

Regards

sunny_talwar

What are you hoping to see in this case? Does A get calculated for both 1 and 3? If that is what you need then change your calculated dimension to this

=Aggr(
FirstSortedValue({<[update date] = {"$(='<=' & Max([update date]))"}>}Rating, -[update date])
, [User Name], Rating)

 

sagarjagga
Creator
Creator
Author

as per my requirement, A should be calculated for highest rating among ratings. for below sample

User NameRatingupdate date
A110/11/2018
A310/11/2018
b110/15/2018
c211/1/2018
d011/1/2018
A211/5/2018
c311/6/2018

 

output should look like

if we select a date as 11/4/2018 

Ratingcount of user name
11 (B)
2

1 (as c)

3

1(A)

 
sunny_talwar

In that case try this

=Aggr(
FirstSortedValue({<[update date] = {"$(='<=' & Max([update date]))"}>}Rating, -([update date] + (Rating/1E10)))
, [User Name])
sagarjagga
Creator
Creator
Author

Thank you so much sunny.