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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
LeHaoNguyen
Contributor III
Contributor III

Replace Zero with Average from User

HI Qlik Community,

i try to create a Table in Qlik Sense to show the time difference between timestamps from each user. in my load i replaced all timestampts over 7200seconds to zero. Now in Qlik Sense i got like following Table:

Product User Time difference

ProductUserTimestampTimediff
0001900111:52:0039
0002900111:52:3960
0003900111:53:390
0004900117:59:000
0001900208:00:00600
0002900208:10:00120
0003900208:12:00180
0004900208:15:000
0005900222:32:0060
0006900222:33:000

 

thats the table i can create right now in qlik sense but i want to replace the zeros in timediff with the average of the user so the 2 zeros from user 9001 gets replaced with (39+60)/2=49,5 and the two zeros from user 9002 gets replaced with (600+120+180+60)/4=240

i tried to make a new column with this expression but it doesnt seem to work:

if(timediff=0,Aggr(Avg ({<timediff={">0"}>}timediff), user),timediff)

Anybody got an idea why my solution doesnt work?

 

Greetings

Le-Hao Nguyen

1 Solution

Accepted Solutions
sunny_talwar

Try this

If(timediff = 0, Avg(TOTAL <User> {<timediff={">0"}>} timediff), timediff)

or

If(timediff = 0, Aggr(NODISTINCT Avg({<timediff={">0"}>} timediff), User), timediff)

View solution in original post

1 Reply
sunny_talwar

Try this

If(timediff = 0, Avg(TOTAL <User> {<timediff={">0"}>} timediff), timediff)

or

If(timediff = 0, Aggr(NODISTINCT Avg({<timediff={">0"}>} timediff), User), timediff)