Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Capture date when a flag is updated only

Hi.

 

I have three columns in a table; created_at, updated_at and flag. When a user gets created, both created_at and updated_at are the same value. The flag can be either 0 or 1; 0 if the user is a guest user and 1 if they are registered. A guest can later register and this flag is updated from 0 to 1. When they register, the updated_at is also updated to the date the user registers. 

 

Problem is, the updated_at property not only updates when a guest converts to a registered user, but also when the user edits anything in their profile. It's basically the property to show the user 'record' was modified somehow.

 

What I want is a measure/calculated column that captures the updated_at date ONLY as soon as the flag changes from 0 to 1; when the updated_at updates again, I don't want the new measure to have that. How would I do that?

  • Hi Anonymous 

     

    If you have all change history/log in data source table, we can consider using the date of the first flag '1' as the registered date for a registered user.  

     

    If you only have latest updated data in data source table, we can not capture the registered date with Power BI. In Power BI, every refresh is a full refresh which reimports data from data sources and do transformations & calculations on these new data again. We cannot store a historical calcualtion result in the model. In this case, you would better consider adding a "registered_at" column in the data source table. This column captures a date when a user's flag turns from 0 to 1 to store his registered date and won't change later. 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

5 Replies

  • Anonymous you cannot do that until you have a history/log of all the changes and also that history identifies what is changed. if the updated_at changes when any value in the record is changed, and there is no history/log, nothing can be done. You need to store the changes at the backend first (in your database) and then you can show updated_at for that specific use case. it is more of a backend data issue rather than power bi stuff.

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi Anonymous 

     

    If you have all change history/log in data source table, we can consider using the date of the first flag '1' as the registered date for a registered user.  

     

    If you only have latest updated data in data source table, we can not capture the registered date with Power BI. In Power BI, every refresh is a full refresh which reimports data from data sources and do transformations & calculations on these new data again. We cannot store a historical calcualtion result in the model. In this case, you would better consider adding a "registered_at" column in the data source table. This column captures a date when a user's flag turns from 0 to 1 to store his registered date and won't change later. 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

  • Anonymous , when do want this to happen, at the time of data load?

    Or do you have a record of the user for each date with a flag ?

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      I have the Power BI in scheduled refresh, so every time the data is refreshed. 

       

      The flag exists for all users; if it's 1 from the start, it means he registered immeditately, if it's 0 it means the user is in guest mode. Guest users who converted to registered users (flag 0 to 1) will have the new measure/column as a date while the users who already registered from the start will have it as null. 

       

      Table looks something like this:

       

      user_idcreated_atupdated_atflag
      120/10/202120/10/20211
      220/12/2021null0

       

      Note again that the updated_at also updates when the user edits their info. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hate to bump threads, but any help would be appreciated on this. Curently blocking a lot of progress from my side.