Average of duration between 2 timestamp

Hi, I’d like to calculate the total of watching time and the average of watching time per username but the result of the average seems incorrect. Thanks in advance !


avgOver(dateDiff({join_stream_time}, {leave_stream_time}, ‘HH’), [{pub_login_name}], PRE_AGG)
image

Hi @thecuon119,
what is the result when you calculate the diff on username level? e.g. your first row.
Maybe you can create a new field “time_diff” and check the if calculation is right.
BG

sorry but how come i perform that diff on username level ?

image
image


So weird !

Are there more than one entry for the “pub_login_name”? Because currently its a SUM.
Could you try to use it as dimension field?

pub_login_name is in string type, the sum of test 1 is the sum of the datediff above

pub_login_name = username in athena

But there is only one row? Becaus it seem not. Somewhere it is grouped and summarizied.


No, it isn’t

Could you pls move the “test1” into “Group by”?

I knew it, i gotta use max :max(dateDiff({join_stream_time}, {leave_stream_time}, ‘HH’), [{pub_login_name}])

But that shows me you have more than one value. If you change the aggregation from Sum to Count, in the old simple dateDiff version you should see it.

ah yeah, here it is


it is test1: dateDiff({join_stream_time}, {leave_stream_time}, ‘HH’)

1 Like

Maybe you missed a filter on the table? I see you have a date control.

yeah but date control isn’t related in this case, i just want to calculate the total watching time

But you have to be careful with Max, because Max doesn’t have to be the current/last one.

Idk why it’s transparently null but result is still (7+7+7+7…) = 49

yeah i’m so confused

You could use all dimension fields and check where the 7 records are located.