Forum Discussion

fn_Saurav's avatar
fn_Saurav
Frequent Visitor
3 years ago

Generate unique id based on timestamp

HI Everyone,

 

I have a dataset that basically has user chat history (of interaction with our chatbot) with hashed user Id and timestamp data.

 

 

I have to generate "some kind of conversation id". The logic is as follows:

 

1) A user can have multiple conversations with the chatbot.

2) If the messages are more than one hour apart, they will be different conversations with different conversation Id.

 

The pseudo logic that I have thought of is to :

1) create partition by the hashed user id and sort by timestamp ascending order.

2) create a new index column starting from 0.

3) in each row check if current(timestamp) - previous(timestamp) > 1hr then previous(index) +1 else previous(index)

4) group by hashed user Id and index --> create a new column (conversation id) where value = hashed user Id + index

 

This logic seems great if we are working with SQL sources but im finding it very difficult to implement it via dax/m query.

So my question is : can this be implemented? Is there a better way to do this?

Any help will be appreciated!

 

Regards,